2016-06-08 25 views
0

我想使用AngularJS的多個視圖使用ng-view和routeProvider,但它不工作。能否請你幫忙?以下是鏈接到我的整個項目普拉克:如何使用ng-view和routeProvider加載多個視圖?

multiple views project

下面是index.html頁面:

<!DOCTYPE html> 
<html lang="en" ng-app="myApp"> 

<head> 
    <meta charset="utf-8" /> 
    <title>AngularJS Routing</title> 
    <script data-require="[email protected]" data-semver="1.4.8" src="https://code.angularjs.org/1.4.8/angular.js"></script> 
    <script data-require="[email protected]*" data-semver="1.4.8" src="https://code.angularjs.org/1.4.8/angular-route.js"></script> 
    <link rel="stylesheet" href="css/app.css" /> 
</head> 

<body> 
    <ul class="menu"> 
    <li> 
     <a href="#/view1.html">view1</a> 
    </li> 
    <li> 
     <a href="#/view2.html">view2</a> 
    </li> 
    </ul> 
    <div>Below you should see the partial view :) ... </div> 
    <div ng-view> 
    <p>ng-view should be loading data from view1.html and view2.html right here but it's not working</p> 
    </div> 



    <script src="app.js"></script> 
    <script src="controllers.js"></script> 
</body> 

</html> 
+0

http://stackoverflow.com/questions/17544558/multiple-ng-view-in-single-template-angular-js –

回答

0

刪除href="#/view1.html".html和`HREF = 「#/ view2.html」

修改

.when('/index', { 
    template: '' 
}) 
.otherwise({ 
    redirectTo: '/index' 
}); 
+0

謝謝您的反饋。這有幫助。不過,無論何時我重新加載index.html頁面,我都會自動重定向到view.html。沒有視圖我看不到index.html!你能幫我弄清楚爲什麼會發生這種情況嗎? –

+0

我修改了我的答案,您需要爲索引添加新的狀態而不需要視圖。 –

+0

謝謝。這現在完美。但我不明白爲什麼你加了這段代碼: –

相關問題