typescript-angular 未知供应商问题

typescript-angular unknown provider issue

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

Error: [$injector:unpr] Unknown provider: 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'
            ]);
}

您正在这样创建服务:

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

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

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

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

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

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

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

应该是:

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

模块

ba.entry

未作为依赖项加载

betting-assistance

module ba {

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

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