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

前端 未结 4 2183
温柔的废话
温柔的废话 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:09

    If you want to use filter inside a controller you have to inject $filter attribute to your controller and can access it like

    $filter('filtername');
    

    You can use like

    function myCtrl($scope, $filter)
    {
        $filter('filtername')(arg1,arg2);
    }
    

提交回复
热议问题