Tag: 延迟的

如何在Angular.js中推迟path定义?

我已经configuration了所有用户login前可以使用的一些基本路由: App.config(function ($routeProvider) { $routeProvider. when('/login', { templateUrl: 'views/login.html', controller: PageStartCtrl.Controller }). otherwise({ redirectTo: '/login' }); }); 所以用户可以做的唯一事情就是login。在用户login后,我想要注册其他的路由,例如: $http .post('api/Users/Login', { User: userName, Password: userPassword }) .success(function (response : any) { App.config(function ($routeProvider) { $routeProvider .when('/dashboard', { templateUrl: 'part/dashboard.html', controller: DashboardCtrl.Controller }); }); 但是,我想我应该只调用一次.config方法,因为$ routeProvider是一个全新的实例,对/ login路由一无所知。 进一步的debugging表明,当parsing视图更改时,会使用$ resourceProvider的第一个实例。 问:以后如何注册路线有办法吗? 从路由和模板dynamic添加到$ routeProvider的解决scheme可能工作,但相当丑陋(涉及全局variablesnastyGlobalReferenceToRouteProvider )。