wikiApp.config(['$routeProvider','authService',
function($routeProvider,authService) {
var admin = authService.getLoggedin();
$routeProvider
.when('/hjem',{
templateUrl: 'partials/homeContent.html',
admin: false
})
.when('/articles/:article',{
templateUrl: 'partials/articles.html',
admin: false
})
.when('/newArticle',{
templateUrl: 'partials/postArticle.html',
controller: 'articleController',
admin: true
})
authService.getLoggedin() 根据用户是否登录返回 false 或 true。如果不允许,我不想让他们访问 URL。
但我得到这个错误:
错误:[$injector:modulerr] 无法实例化模块 wikiApp,原因如下:
[$injector:unpr] 未知提供者:authService
最佳答案
因此,要在配置中注入(inject)服务,您只需要通过在其名称中添加“提供者”来调用服务的提供者。
angular.module('myApp')
.service('FooService', function(){
//...etc
})
.config(function(FooServiceProvider){
//...etc
});
关于angularjs - 如何在 AngularJS 中将服务注入(inject) app.config,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22682753/