0
我看到了一些示例如何將自定義提供程序插入角度的.config
,但我未能正確執行此操作。角度.config中的自定義提供程序
我有一個供應商:
(function() {
var app = angular.module('application.providers', ['application.services'])
app.provider('accessProvider', function() {
this.$get = ['userServices',
function(userServices) {
var auth = {}
auth.action = function(action, roles) {
auth[action] = angular.copy(roles)
}
auth.action('sell', [...])
auth.can = function(action) {
var userRole = userServices.getRole()
return auth[action].reduce(function(prev, now) {
return prev || (now === userRole)
}, false)
}
return auth
}
]
})
})()
,當我在這裏定義我的路線:
(function() {
var app = angular.module('application.configRoutes', ['ngRoute', 'application.providers'])
app.config(['$routeProvider', '$locationProvider', 'accessProvider',
function($routeProvider, $locationProvider, accessProvider) {
...
我收到以下錯誤:
Uncaught Error: [$injector:modulerr] Failed to instantiate module landingPage due to:
Error: [$injector:modulerr] Failed to instantiate module application.configRoutes due to:
Error: [$injector:unpr] Unknown provider: accessProvider
這是我的實例我的應用:
var app = angular.module('landingPage', [
'application.configRoutes',
'application.directives',
'application.controllers',
'application.translate',
'application.flash',
'application.customInterceptors'
])
我在providers.js
之前加載存儲services.js
的文件,然後才加載configRoutes.js
。