-
Notifications
You must be signed in to change notification settings - Fork 27.4k
docs(guide/Filters): describe your change... #11915
Conversation
I had a really hard time understanding that if I use a custom filter from a controller or service, I needed to add the string "Filter" to the name of the filter when listing it as a dependency of my controller or service. I hope, by adding this example of the custom filter, "name", it becomes apparent. It's weird that a developer could refer to the custom filter by it's name in a view, like `<div ng-repeat="user in array | name:'a'">{{user.name}}</div>` but they have to refer to it by "nameFilter" from a controller or service instead of just "name". In this example, the error message from angular is really unhelpful when the controller fails to refer to the "name" filter by the string "nameFilter". The error is, "Error: [$injector:unpr] Unknown provider: nameProvider <- name <- FilterController".
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project, in which case you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
I signed it! Sent from my iPhone
|
CLAs look good, thanks! |
FWIW, this is explained (clearly imo) in the Filters section of the Developer Guide. |
@gkalpak But we are in the filters guide |
@Narretz, indeed :) I guess I meant in the "Using filters in controllers, services, and directives" section of the Filters guide, where it says:
|
After suddenly struggling with this same issue (despite having been using custom filters within templates for a long time), I'd like to urge you to merge this PR. In my opinion, the proposed 'nameFilter' example makes a much clearer example of what's happening than the 'filterFilter' example. |
I've made a change for this, but did not include this new example. It doesn't really add anything new and might be confusing actually. It's explained in the first paragraph how to require filters - I've made the style more explicit. I've also added an example of using the filter in the controller in the custom filter example. |
I had a really hard time understanding that if I use a custom filter from a controller or service, I needed to add the string "Filter" to the name of the filter when listing it as a dependency of my controller or service. I hope, by adding this example of the custom filter, "name", it becomes apparent.
It's weird that a developer could refer to the custom filter by it's name in a view, like
<div ng-repeat="user in array | name:'a'">{{user.name}}</div>
but they have to refer to it by "nameFilter" from a controller or service instead of just "name".In this example, the error message from angular is really unhelpful when the controller fails to refer to the "name" filter by the string "nameFilter". The error is, "Error: [$injector:unpr] Unknown provider: nameProvider <- name <- FilterController".