У меня есть следующий компонент, в который я пытаюсь внедрить службу:
angular.
module('phoneList').
component('phoneList', {
templateUrl: '/static/common/angular/phone-list/phone-list.template.html',
controller: ['$http', 'authenticationService',
function PhoneListController($http, authenticationService) {
var self = this;
authenticationService.authenticate().then(function(){
console.log('it worked!!!!!!!!');
});
}
]
});
Сервис выглядит так:
angular.module('authentication').factory('authenticationService', function($http, $se){
function authenticate(){
$http.post('/o/token/', data, config)
.success(function (data, status, headers, config) {
console.log('auth service: '+data['access_token']);
$sessionStorage.access_token = data['access_token'];
});
}
function getToken(){
return $sessionStorage.access_token;
}
return {
authenticate:authenticate,
getToken:getToken
};
});
Мой phone-list.module.js выглядит так:
angular.module('phonecatApp', [
'phoneList',
'authentication',
]);
angular.module('phoneList', ['authentication']);
Когда я запускаю это, я получаю сообщение об ошибке:
Uncaught ReferenceError: служба аутентификации не определена
Когда я помещаю «authenticationService» в «», я получаю сообщение об ошибке:
Ошибка [$injector:unpr] служба аутентификации
angular.module('phonecatApp')
дважды, что означает, что вы хотите создать модуль дважды, что невозможно. В вашей ошибке тоже ошибкаauthtenticationService
(может опечатка?). - person A1rPun   schedule 12.09.2016