我想解决承诺加载当前用户为我的应用程序的所有页面。
现在我重复每个$ routeProvider.when()我的路由的解决方案。
现在我重复每个$ routeProvider.when()我的路由的解决方案。
$routeProvider.when('/users/edit/:userId',{ templateUrl: 'app/app/assets/partials/user-edit.html',controller: 'UserEditController',resolve:{ 'currentUser':function( UserService){ return UserService.getCurrentUser(); } } }); $routeProvider.when('/staff_profil/edit',{ templateUrl: 'app/app/assets/partials/profil-edit.html',controller: 'ProfilEditController',resolve:{ 'currentUser':function( UserService){ return UserService.getCurrentUser(); } } });
你可以随时用
$routeProvider
自己的实现包装现有的when方法。
var myModule = angular.module('myModule',['ngRoute']) .config(['$routeProvider',function($routeProvider){ var originalWhen = $routeProvider.when; $routeProvider.when = function(path,route){ route.resolve = { 'currentUser':function( UserService){ return UserService.getCurrentUser(); } }; return originalWhen(path,route); }; }]);
你可能想添加一些错误检查在那里,并使用像underscores defaults
方法,而不是只覆盖现有的解决方案属性,但至少这样,你可以保证所有的路由将有你想要的。
原文地址:https://www.jb51.cc/angularjs/145304.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。