角度ルーティングが働いていません
-
21-12-2019 - |
質問
angularjsで働いていないルーティングについて多くの質問があることを知っています。私は同じ問題を抱えていて、私はこの質問をまだ投稿することにした何百もの答えを経験した後、私はもう二度と転記することにしました。C:\ intepub \ wwwroot \ angular \のルートフォルダにある3つのファイルがあり、これはIISの下でテストされていることを意味します。これで、このURLをブラウザに置くと、http://localhost/angular/index.html
、ブラウザはそれを:http://localhost/angular/index.html#/
とページ上のテキストは次のとおりです。テストroutes
しかし、コードによると、login.htmlに進むべきです。そして、http://localhost/angular/index.html#/test
を入力すると、それでも同じテキストが表示されます。テストルート。
任意のアイデア?
ありがとう
コードを以下に示します。
index.html
<!DOCTYPE html>
<html ng-app="app">
<head></head>
<body>
<div>
Testing routes
<div ng-view=""></div>
</div>
<script src="dep/angular/angular.js"></script>
<script src="dep/angular/angular-route.js"></script>
<script>
var app = angular.module('app', ['ngRoute']);
app.config(appRouter);
function appRouter($routeProvider, $locationProvider)
{
$routeProvider
.when('/',
{
templateURL: 'login.html'
})
.when('/test',
{
templateURL: 'test.html'
})
.otherwise({tempate: "otherwise"});
}
</script>
</body>
</html>
.
login.html
<div>
Login Page
</div>
.
test.html
<div>
Test page
</div>
. 解決
templateUrl
templateURL
を使用します。
これは$ routeproviderのプロパティです。 http://docs.angularjs.org/api/ngroute/provider/$ routeprovidered//a>
これは単にチュートリアルの使い方です: http://docs.angularjs.org/tutorial/step_07
他のヒント
あなたのマークアップを定義した方法:
<div>
Testing routes
<div ng-view=""></div>
</div>
.
ngが<div ng-view="">
要素内に表示コンテンツを置くと常に "テストルート"を表示します。あなたはそれを適切なものに変えるべきです。
これを試して、コントローラーを逃した
function appRouter($routeProvider, $locationProvider)
{
$routeProvider
.when('/',
{
templateURL: 'login.html',controller: 'loginCtrl'
})
.when('/test',
{
templateURL: 'test.html',controller: 'testCtrl'
})
.otherwise({tempate: "otherwise"});
}
.
login.html
<div ng-controller="loginCtrl">
Login Page
</div>
.
test.html
<div ng-controller="testCtrl">
Test Page
</div>
.
「起動ページ」ページ「TI Index」ページ
を設定する必要があります。
ソリューションエクスプローラのindex.htmlページを右クリックして、表示されているポップアップの[開始ページとして設定]オプションをクリックします。