关于Angular 路由控制的两种写法
下面的这第一种通过config的$routeProvider配置路由,这样比较繁琐,没有统一管理,不是最好的选择
.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/view1', {
templateUrl: 'view1/view1.html',
controller: 'View1Ctrl'
});
}])
.controller('View1Ctrl', [function () {
}]);
第二种通过component()方法让路由在app.js中进行统一管理统一在app.js中用config()方法进行统一管理
$routeProvider.when('/view1', {
template: '<view1></view1>'
}).when('/view2', {
template: '<view1></view1>'
});
.component('view1', {
templateUrl: 'view1/view1.html',
controller: function () {
}
})
所有在index.html引用angularjs的页面脚本都可以统一起来
本文介绍了Angular中两种不同的路由配置方法:一种是使用$routeProvider配置路由,另一种是通过component()方法集中管理路由。后者更加简洁,便于统一管理和维护。
1227

被折叠的 条评论
为什么被折叠?



