Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

docs(guide/Filters): describe your change... #11915

Closed
wants to merge 1 commit into from

Conversation

swick7
Copy link

@swick7 swick7 commented May 20, 2015

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".

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".
@googlebot
Copy link

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!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@swick7
Copy link
Author

swick7 commented May 20, 2015

I signed it!

Sent from my iPhone

On May 20, 2015, at 10:32 AM, googlebot notifications@github.com wrote:

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!) and we'll verify. Thanks.

If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
If you signed the CLA as a corporation, please let us know the company's name.

Reply to this email directly or view it on GitHub.

@googlebot
Copy link

CLAs look good, thanks!

@gkalpak
Copy link
Member

gkalpak commented May 20, 2015

FWIW, this is explained (clearly imo) in the Filters section of the Developer Guide.

@Narretz Narretz added this to the Backlog milestone Jun 5, 2015
@Narretz
Copy link
Contributor

Narretz commented Jun 5, 2015

@gkalpak But we are in the filters guide

@gkalpak
Copy link
Member

gkalpak commented Jun 5, 2015

@Narretz, indeed :) I guess I meant in the "Using filters in controllers, services, and directives" section of the Filters guide, where it says:

You can also use filters in controllers, services, and directives. For this, inject a dependency with the name <filterName>Filter to your controller/service/directive. E.g. using the dependency numberFilter will inject the number filter.

@bradhenslee
Copy link

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.

@Narretz
Copy link
Contributor

Narretz commented Jan 20, 2016

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants