admin管理员组文章数量:1024016
I have an angularjs SPA application with an index.html page as the main template and the rest of the views are loaded as subviews in an ng-view tag. I'm using a twitter bootstrap template for the site so the template has a login page thats different from the rest of the pages. Is there a way to have multiple main template pages, one for the login page and one for everything else? I've been trying to figure out how to specify a different page in the route provider but I haven't been able to figure out how to specify a page rather than a partial view as the templateURL or if thats even possible.
I'm new to angularjs so i'm not sure what the best way to handle this situation.
Thanks
I have an angularjs SPA application with an index.html page as the main template and the rest of the views are loaded as subviews in an ng-view tag. I'm using a twitter bootstrap template for the site so the template has a login page thats different from the rest of the pages. Is there a way to have multiple main template pages, one for the login page and one for everything else? I've been trying to figure out how to specify a different page in the route provider but I haven't been able to figure out how to specify a page rather than a partial view as the templateURL or if thats even possible.
I'm new to angularjs so i'm not sure what the best way to handle this situation.
Thanks
Share Improve this question asked Oct 23, 2013 at 13:05 MBUMBU 5,09812 gold badges63 silver badges99 bronze badges 1- I think this post answers your question: stackoverflow./questions/11541695/… – user3393575 Commented Mar 10, 2014 at 18:15
2 Answers
Reset to default 2You are on the right track with RouteProvider
angular.module('mymodule', ['ngRoute'])
.config(function($routeProvider) {
$routeProvider.
when('/index.html/page1/', {templateUrl : './templates/template1.html'}).
when('/index.html/page2/', {templateUrl : './templates/template2.html'}).
otherwise({redirectTo : '/index.html/page1/'});
});
You would have to do this using ng-include
. Your main view should look like
<body ng-app>
<div id='topNav' ng-include='templateUrl' ng-controller='topNavController'></div>
<div id='left' ng-include='templateUrl' ng-controller='leftNavController'></div>
<div ng-view>
</body>
The templateUrl
can be from server or preloaded onto the client using <script>
tag.
The javascript would look like.
function topNavController($scope, $route, $location) {
//Check using $route or $location if login view is loaded
// if yes $scope.templateUrl='loginTopNavTemplateUrl'
//else $scope.templateUrl='mainNavTemplateUrl'
}
Check documentation for ng-include
, $route
and $location
to see how how these elements work.
I have an angularjs SPA application with an index.html page as the main template and the rest of the views are loaded as subviews in an ng-view tag. I'm using a twitter bootstrap template for the site so the template has a login page thats different from the rest of the pages. Is there a way to have multiple main template pages, one for the login page and one for everything else? I've been trying to figure out how to specify a different page in the route provider but I haven't been able to figure out how to specify a page rather than a partial view as the templateURL or if thats even possible.
I'm new to angularjs so i'm not sure what the best way to handle this situation.
Thanks
I have an angularjs SPA application with an index.html page as the main template and the rest of the views are loaded as subviews in an ng-view tag. I'm using a twitter bootstrap template for the site so the template has a login page thats different from the rest of the pages. Is there a way to have multiple main template pages, one for the login page and one for everything else? I've been trying to figure out how to specify a different page in the route provider but I haven't been able to figure out how to specify a page rather than a partial view as the templateURL or if thats even possible.
I'm new to angularjs so i'm not sure what the best way to handle this situation.
Thanks
Share Improve this question asked Oct 23, 2013 at 13:05 MBUMBU 5,09812 gold badges63 silver badges99 bronze badges 1- I think this post answers your question: stackoverflow./questions/11541695/… – user3393575 Commented Mar 10, 2014 at 18:15
2 Answers
Reset to default 2You are on the right track with RouteProvider
angular.module('mymodule', ['ngRoute'])
.config(function($routeProvider) {
$routeProvider.
when('/index.html/page1/', {templateUrl : './templates/template1.html'}).
when('/index.html/page2/', {templateUrl : './templates/template2.html'}).
otherwise({redirectTo : '/index.html/page1/'});
});
You would have to do this using ng-include
. Your main view should look like
<body ng-app>
<div id='topNav' ng-include='templateUrl' ng-controller='topNavController'></div>
<div id='left' ng-include='templateUrl' ng-controller='leftNavController'></div>
<div ng-view>
</body>
The templateUrl
can be from server or preloaded onto the client using <script>
tag.
The javascript would look like.
function topNavController($scope, $route, $location) {
//Check using $route or $location if login view is loaded
// if yes $scope.templateUrl='loginTopNavTemplateUrl'
//else $scope.templateUrl='mainNavTemplateUrl'
}
Check documentation for ng-include
, $route
and $location
to see how how these elements work.
本文标签: javascriptAngularJS application multiple pagesStack Overflow
版权声明:本文标题:javascript - AngularJS application multiple pages - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745498913a2153297.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论