Angularjs 工厂中工厂的角度依赖注入返回空对象
所以我有一个非常奇怪的问题,我不能将一个工厂注入另一个工厂,但只能在一个特定的工厂 所以我有以下代码 控制器:Angularjs 工厂中工厂的角度依赖注入返回空对象,angularjs,dependency-injection,Angularjs,Dependency Injection,所以我有一个非常奇怪的问题,我不能将一个工厂注入另一个工厂,但只能在一个特定的工厂 所以我有以下代码 控制器: angular.module('cheetah').controller("NewSprintController", ["$rootScope", "$scope", "$state", "EventService", "$modalInstance", "$timeout", "ErrorService", "NewSprintLogicService", "EventIdenti
angular.module('cheetah').controller("NewSprintController", ["$rootScope", "$scope", "$state", "EventService", "$modalInstance", "$timeout", "ErrorService", "NewSprintLogicService", "EventIdentifierService", function NewSprintController($rootScope, $scope, $state, evs, $modalInstance, $timeout, err, nsl, eis) {
$scope.Sprint = nsl.CreateSprint();
...
我将NewSprintLogicService注入其中,我将其解析为nsl。这很好,如果我们再看看NewSprintLogicService,它看起来是这样的:
angular.module("cheetah").factory("NewSprintLogicService", ["ApiService", function NewSprintLogicService(api) {
return {
CreateSprint: function () { return api.Sprint(); },
GetAll: function() {
...
现在,我在这里注入我的ApiService,这就是它变得棘手的地方。我要注射一个空物体。此模式适用于不同的控制器和逻辑服务。Sprint属性实际上是在ApiService中定义的
请澄清,以下是我的服务:
angular.module("cheetah").factory("ApiService", ["$resource", function ApiService($resource) {
return {
UserStory: $resource("/api/UserStory/:userStoryId", { userStoryId: "@Id" }),
...
在LogicService中尝试使用ApiService时,除了无法从undefined读取属性和undefined不是函数之外,我没有收到任何错误。确实,尝试将问题表述为Stackoverflow问题会有所帮助。在这种情况下,我意识到我的LogicService中缺少了一个新的服务,所以应该是这样的:
angular.module("cheetah").factory("NewSprintLogicService", ["ApiService", function NewSprintLogicService(api) {
return {
CreateSprint: function () { return new api.Sprint(); },
...
简单的错误