Неизвестный поставщик: $state

Здравствуйте, у меня возникли некоторые проблемы с внедрением зависимостей через сервис $injector.
Я новичок в angular, поэтому я объясню, как я это вижу с точки зрения контейнера IoC.

Прежде всего, проблема: $ инжектор не может разрешить состояние $.

core.js

(function() {
    'use strict';
     angular.module('app.core',['ui.router'])
         .config(function($stateProvider,$state){
           // ......
     });
}());

Вот ошибка:

  Uncaught Error: [$injector:modulerr] Failed to instantiate module app due      to:
  Error: [$injector:modulerr] Failed to instantiate module app.core due to:
  Error: [$injector:unpr] Unknown provider: $state

Я не думаю, что трассировка стека имеет большое значение здесь... но на всякий случай я разместил ее в нижней части вопроса:

Index.html: я просто хотел показать, где и в каком порядке я ссылаюсь на мои файлы.js.

    <head>
    ....  <!-- pointing out that my .js are not here --> 
    </head>
    <body>

        <script src="bower_components/jquery/dist/jquery.js"></script>
        <script src="bower_components/angular/angular.js"></script>
        <script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>

        <script src="components/core/lib/core.js"></script>
        **<!-- relevant to the EDIT part below -->
        <script src="components/something/something.js"></script>** 
    </body>

Как я понимаю, рецепт поставщика Angular:

$stateProvider is the service provider which registers $state service to the IoC($injector) and does so by exposing $get member which the IoC knows to treat in a special way.

если '$stateProvider' был создан и может быть введен сам по себе, почему он не зарегистрировал службу '$state' в IoC

РЕДАКТИРОВАТЬ: более того, позже у меня есть другой модуль, в котором нет проблем с получением службы $ state в качестве зависимости.

something.js

   (function() {
     'use strict';
      angular.module('app.something',['ui.router'])  
           .config(function($stateProvider, $urlRouterProvider,$state) {
             .... no problem receiving '$state' here
       })       
 }());    

РЕДАКТИРОВАТЬ 2: мой плохой, он не работает ни в одном конфиге VISHAL DAGA был прав.

Трассировка стека:

  http://errors.angularjs.org/1.4.8/$injector/unpr?p0=%24state
  at http://localhost:9000/bower_components/angular/angular.js:68:12
  at http://localhost:9000/bower_components/angular/angular.js:4334:19
  at getService      (http://localhost:9000/bower_components/angular/angular.js:4482:39)
  at Object.invoke (http://localhost:9000/bower_components/angular/angular.js:4514:13)
  at runInvokeQueue (http://localhost:9000/bower_components/angular/angular.js:4429:35)
  at http://localhost:9000/bower_components/angular/angular.js:4438:11
    at forEach     (http://localhost:9000/bower_components/angular/angular.js:340:20)
    at loadModules   (http://localhost:9000/bower_components/angular/angular.js:4419:5)
    at http://localhost:9000/bower_components/angular/angular.js:4436:40
    at forEach      (http://localhost:9000/bower_components/angular/angular.js:340:20)
 http://errors.angularjs.org/1.4.8/$injector/modulerr?p0=app.core&p1=Error%3…    2F%2Flocalhost%3A9000%2Fbower_components%2Fangular%2Fangular.js%3A340%3A20)
    at http://localhost:9000/bower_components/angular/angular.js:68:12
    at http://localhost:9000/bower_components/angular/angular.js:4458:15
    at forEach   (http://localhost:9000/bower_components/angular/angular.js:340:20)
      at loadModules   (http://localhost:9000/bower_components/angular/angular.js:4419:5)
    at http://localhost:9000/bower_components/angular/angular.js:4436:40
    at forEach   (http://localhost:9000/bower_components/angular/angular.js:340:20)
    at loadModules   (http://localhost:9000/bower_components/angular/angular.js:4419:5)
      at createInjector   (http://localhost:9000/bower_components/angular/angular.js:4344:11)
      at doBootstrap   (http://localhost:9000/bower_components/angular/angular.js:1676:20)
      at bootstrap   (http://localhost:9000/bower_components/angular/angular.js:1697:12)
   http://errors.angularjs.org/1.4.8/$injector/modulerr?p0=app&p1=Error%3A%20%…F%2Flocalhost%3A9000%2Fbower_components%2Fangular%2Fangular.js%3A1697%3A12)

2 ответа

Решение

На этапе конфигурирования все его провайдер, поэтому ввод $stateProvider корректен, но не $state.

Удалите $ state, и проблема исчезнет.

Я думаю, что вы смешиваете $state с $stateProvider.state, Смотрите ниже для правильного использования

(function() {
    'use strict';
     angular.module('app.core',['ui.router'])
         .config(function($stateProvider){
           $stateProvider
            .state('default', {....
     });
}());
Другие вопросы по тегам