2017-06-21 3 views
1

私はangularJSを初めて使い、anglejsルーティング上のvisual studioのチュートリアルに取り組んでいますが、URLリンクを変更してもng-viewは変更されません。 これはこれは私が/index.html#/homeへのURLを変更するにもかかわらず、div要素の内容は「常に私のcontroller.jsVisual StudioでのAngularJSルーティングについて2015

var app = angular.module('mainApp', ['ngRoute']); 
app.config(function($routeProvider) { 
$routeProvider 
    .when('/home', { 
    template: 'Home' 
}) 
.when('/anotherpage', { 
    template: 'another page' 
}) 
.otherwise({ 
    template: 'index' 
}); 
}); 

である私のindex.html

<!DOCTYPE html> 
<html> 
<head> 
<title></title> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> 
<script src="controller.js"></script> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-route.js"></script> 
<meta charset="utf-8" /> 
</head> 
<body ng-app="mainApp"> 
<a href="#/home">home</a> 
<a href="#/anotherpage">another page</a> 
<div ng-view></div> 
</body> 
</html> 

ですインデックス '。誰もこれのための任意のソリューションを提案することができます。

答えて

0

以下のようにhtmlを変更してください。

<a href="#!home">home</a> 
    <a href="#!anotherpage">another page</a> 
    <div ng-view></div> 
+0

正常に機能しました。ありがとうございました。 –

関連する問題