AngularJS - $routeProvider 和 data-ng-view 问题
AngularJS - Issue with $routeProvider and data-ng-view
我有以下 html 页,
- index.html - 有
ng-view
- welcome.html
- app.html - 有很多子页面。所以需要使用
ng-view
我的初始 $routeProvider
是,
$routeProvider
.when('/', {
redirectTo: '/welcome'
})
.when('/welcome',{
templateUrl: 'views/welcome.html',
controller: welcomeCtrl
})
.when('/app',{
templateUrl: 'app.html',
controller: mainCtrl
})
.otherwise({
redirectTo: '/welcome',
});
现在 app.html
中有多个子页面。如何为此添加路由?
我对 AngularJS 比较陌生。我试图在 app.html
中添加 ng-view
并试图在同一个 $routeProvider
中定义路由,但是当我这样做时,我得到了错误,maximum call stack exceeded
错误,并且我的浏览器的内存像任何东西一样增加并且挂起。我严重缺少一些基本的东西
在此先感谢您的帮助。
我建议你使用 angular ui-router:
AngularUI Router is a routing framework for AngularJS, which allows you to organize the parts of your interface into a state machine. Unlike the $route service in the Angular ngRoute module, which is organized around URL routes, UI-Router is organized around states, which may optionally have routes, as well as other behavior, attached.
我有以下 html 页,
- index.html - 有
ng-view
- welcome.html
- app.html - 有很多子页面。所以需要使用
ng-view
我的初始 $routeProvider
是,
$routeProvider
.when('/', {
redirectTo: '/welcome'
})
.when('/welcome',{
templateUrl: 'views/welcome.html',
controller: welcomeCtrl
})
.when('/app',{
templateUrl: 'app.html',
controller: mainCtrl
})
.otherwise({
redirectTo: '/welcome',
});
现在 app.html
中有多个子页面。如何为此添加路由?
我对 AngularJS 比较陌生。我试图在 app.html
中添加 ng-view
并试图在同一个 $routeProvider
中定义路由,但是当我这样做时,我得到了错误,maximum call stack exceeded
错误,并且我的浏览器的内存像任何东西一样增加并且挂起。我严重缺少一些基本的东西
在此先感谢您的帮助。
我建议你使用 angular ui-router:
AngularUI Router is a routing framework for AngularJS, which allows you to organize the parts of your interface into a state machine. Unlike the $route service in the Angular ngRoute module, which is organized around URL routes, UI-Router is organized around states, which may optionally have routes, as well as other behavior, attached.