未知提供商:ServiceProvider< - 服务

时间:2017-09-04 23:42:45

标签: angularjs

我对角度很新,我一直试图解决这个问题,而且我似乎没有任何进展。 我以前在选择器组件上调用了服务,它工作正常,但现在我有2个选择,第二个是相同的列表,但根据第一个选择的内容进行过滤,所以我将它移动到过滤器组件包含两个选项,它不再起作用。

Old thing-selector.controller.js

export default function ThingSelectorController($scope, ThingService) {
  'ngInject';

  ...

  this.getThings = () => ThingService.find().then((things) => {        
    return things;
  });
}


新的filter.controller.js

export default function FilterController($scope, $state, ThingService) {
  'ngInject';
  this.things = [];
  ...

  this.$onInit = () => {
    ThingService.getThings().then((things) => {
       this.things = things;

    });      
  }


filter.component.js

import template from './filter.component.html';
import controller from './filter.controller';

export const FilterComponent = {
  template,
  controller
};

export default FilterComponent;


component.js

imports...

export default angular.module('app.components', [])
.component('thingSelector',  ThingSelectorComponent)
.component('thingWrapper',   ThingWrapperComponent)
.component('filterBox',      FilterComponent)  
...
.name;


apps.js

import { SomethingElseService, ThingService } from './services';

angular.module('myApp', [
  uiRouter,
  uiSelect,
  ngSanitize,
  Components
])
.component('homePage',      HomeComponent)
.component('somethingElsePage', SomethingElseListComponent)

.service('ThingsService',    ThingsService)
.service('SomethingElseService', SomethingElseService)
...


错误

angular.js:13708 Error: [$injector:unpr] Unknown provider: ThingServiceProvider <- ThingService http://errors.angularjs.org/1.5.7/$injector/unpr?p0=ThingServiceProvider%20%3C-%20ThingService
    at http://localhost:3000/app.js:7969:13
    at http://localhost:3000/app.js:12403:20
    at Object.getService [as get] (http://localhost:3000/app.js:12556:40)
    at http://localhost:3000/app.js:12408:46
    at getService (http://localhost:3000/app.js:12556:40)
    at injectionArgs (http://localhost:3000/app.js:12580:59)
    at Object.invoke (http://localhost:3000/app.js:12602:19)
    at $controllerInit (http://localhost:3000/app.js:18135:35)
    at nodeLinkFn (http://localhost:3000/app.js:17048:35)
    at compositeLinkFn (http://localhost:3000/app.js:16411:14) <ui-view class="ng-scope">

0 个答案:

没有答案