2016-06-08 46 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

谢谢。这现在完美。但我不明白为什么你加了这段代码: –

相关问题