0

在 Controller 中注入 StateService 时遇到此问题

错误:[$injector:unpr] 未知提供者:StateServiceProvider <- StateService

//Service
module ba.entry {
  export class StateService{
        constructor () {}
  }

  angular
      .module('ba.entry')
      .service('ba.entry.StateService', StateService);
}


// Controller
module ba.entry {

    export class StateController {

        static $inject = ['$scope', 'ba.entry.StateService'];

        constructor (public $scope: Scope, stateService) {}
    }

    angular
        .module('ba.entry')
        .controller('ba.entry.StateController', StateController);

}

// 应用配置

module ba {

    'use strict';
        angular.module('ba.entry', []);

        angular
            .module('betting-assistance', [
                'ui.router',
                'AutoCompleteApp'
            ]);
}
4

2 回答 2

0

您正在创建这样的服务:

.service('ba.entry.StateService', StateService);

你的 $inject 语句是这样定义的

static $inject = ['$scope', 'StateService'];

问题是 $inject 在注册到角度模块时采用正在使用的字符串,因此将您的注入语句更改为...

static $inject = ['$scope', 'ba.entry.StateService'];

我看到的另一个问题是您正在尝试将服务作为模块注入......

angular.module('ba.entry', ['ba.entry.StateService']);

应该:

angular.module('ba.entry', []);
于 2015-05-28T13:13:11.757 回答
0

模块

ba.entry

未作为依赖项加载

投注协助

module ba {

    'use strict';
        angular.module('ba.entry', []);

        angular
            .module('betting-assistance', [
                'ui.router',
                'ba.entry',
                'AutoCompleteApp'
            ]);
}
于 2015-05-28T17:28:51.157 回答