喷油器已创建。无法注册模块 [英] injector already created. can not register a module
本文介绍了喷油器已创建。无法注册模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好我是一个新的蜜蜂角JS,并试图在一个适当的方式TDD出来的东西,但测试时我收到此错误。结果
喷油器已经创建,无法注册模块!
guys i am a new bee to Angular JS and was trying to make something out of it in a proper TDD way, but while testing i am getting this error.
Injector already created, can not register a module!
这是我说的服务。
bookCatalogApp.service('authorService', ["$resource", "$q", function($resource, $q){
var Author =$resource('/book-catalog/author/all',{},{
getAll : { method: 'GET', isArray: true}
});
var authorService = {};
authorService.assignAuthors = function(data){
authorService.allAuthors = data;
};
authorService.getAll = function(){
if (authorService.allAuthors)
return {then: function(callback){callback(authorService.allAuthors)}}
var deferred = $q.defer();
Author.getAll(function(data){
deferred.resolve(data);
authorService.assignAuthors(data);
});
return deferred.promise;
};
return authorService;
}]);
这是上面的服务测试
describe("Author Book Service",function(){
var authorService;
beforeEach(module("bookCatalogApp"));
beforeEach(inject(function($injector) {
authorService = $injector.get('authorService');
}));
afterEach(function() {
httpBackend.verifyNoOutstandingExpectation();
httpBackend.verifyNoOutstandingRequest();
});
describe("#getAll", function() {
it('should get all the authors for the first time', function() {
var authors = [{id:1 , name:'Prayas'}, {id:2 , name:'Prateek'}];
httpBackend.when('GET', '/book-catalog/author/all').respond(200, authors);
var promise = authorService.getAll();
httpBackend.flush();
promise.then(function(data){
expect(data.length).toBe(2)
});
});
it('should get all the authors as they have already cached', function() {
authorService.allAuthors = [{id:1 , name:'Prayas'}, {id:2 , name:'Prateek'}];
var promise = authorService.getAll();
promise.then(function(data){
expect(data.length).toBe(2)
});
});
});
})
任何帮助将AP preciated。
Any help will be appreciated.
推荐答案
如果你是混合调用模块('someApp')
和注入($ someDependency)
你会得到这个错误。
If you are mixing calls to module('someApp')
and inject($someDependency)
you will get this error.
您为模块('someApp')所有呼叫
您的通话之前,必须进行以注($ someDependency)
All your calls to module('someApp')
must occur before your calls to inject($someDependency)
.
这篇关于喷油器已创建。无法注册模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文