使用自定义筛选器时出现角度“未知提供程序”错误

时间:2018-04-25 07:03:35

标签: javascript angularjs typescript

我正在使用带有打字稿的1.5角。面对Unknown provider: testNameFilterFilterProvider <- testNameFilterFilter

这是我现有的代码

export class TestNameFilter extends AbstractFilter {
    public static factory($injector: angular.auto.IInjectorService): Function {
      return new TestNameFilter($injector).filter;
    }

    public constructor($injector: angular.auto.IInjectorService) {
      super("TestNameFilter", $injector);
    }

    public filter = (text: string, length: any, end: any): string => {
      let state: string = text;
      state = this.toSentenceCase(state);
      return state;
    }

  }

注册

angular.module("myApp").filter(
    "testNameFilter",
    [
      "$injector",
      ($injector: angular.auto.IInjectorService) => new TestNameFilter($injector).filter,
    ]
  );

HTML

 <select 
        ng-options="item as (test.name | testNameFilter)
                    for test in testing">
  <option value=""></option>
</select>

0 个答案:

没有答案