AngularJS 1.x custom filter can't be injected, unknown provider

前端 未结 4 2150
温柔的废话
温柔的废话 2021-02-20 03:15

I\'m trying to create a custom filter, but when I try to inject it into my controller, I get an \'Unknown provider\' error. I have checked and double checked all the references,

4条回答
  •  失恋的感觉
    2021-02-20 04:21

    According to Angular's documentation :

    if you want to use your filter in a template

    then you just need to inject it in your module and then use it like this {{ expression | filter }} or {{ expression | filter:argument1:argument2:... }} .

    doc

    if you want to use your filter in a controller, directive, and stuffs :

    inject a dependency with the name Filter, like this :

    controller('MyController', ['filterFilter', function(filterFilter) {}]);
    

    doc

    so for this particular case :

    angular.module('equiclass.controllers')
      .controller('CourseCtrl', function ($scope, testFilterFilter) {
    
      });
    

提交回复
热议问题