質問

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>
.

役に立ちましたか?

解決

他のヒント

あなたのマークアップを定義した方法:

   <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」ページ

を設定する必要があります。

Enter Image説明

ソリューションエクスプローラのindex.htmlページを右クリックして、表示されているポップアップの[開始ページとして設定]オプションをクリックします。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top