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
을로드합니다.