我已根据其他服务编写了一项服务。但初始化不起作用。
You can find a plunker as showcase
应该接近工作...任何tipps? 提前谢谢!
编辑:现在修复了plunker并可以作为参考。
答案 0 :(得分:1)
您需要将testServiceMockConfig
和testService
从factory
更改为service
,例如:
.service('testServiceMockConfig', function ()
或将它们保存为工厂并在其底部添加return.this;
或者像这样重新构建它们(推荐):
angular.module('testServiceMockConfig', [])
.factory('testServiceMockConfig', function() {
console.log("setup cqrs mock config.");
return {
doLoadItems: function(callback) {
console.log("mock loading data");
if (!this.configuredLoadItems) {
throw Error("The mock is not configured to loadItems().");
}
callback(this.loadItemsError, this.loadItemsSuccess);
},
whenLoadItems: function(success, error) {
this.configuredLoadItems = true;
this.loadItemsSuccess = success;
this.loadItemsError = error;
}
};
});
我还假设loadItems
中的testService
应该致电:
testServiceMockConfig.doLoadItems(callback);
而不是:
testService.doLoadItems(callback);
答案 1 :(得分:1)