| Start |
|---|
| Accessing a filtered list from outside an ng-repeat Occasionally you will want to access the result of your filters from outside the |
| Custom filter to remove values A typical use case for a filter is to remove values from an array. In this example we pass in an array and remove any nulls found in it, returning the array. That would be used in the HTML like or in a controller like |
| Custom filter to format values Another use case for filters is to format a single value. In this example, we pass in a value and we are returned an appropriate true boolean value. Which in the HTML would be used like this: Or in a controller like: |
| Performing filter in a child array This example was done in order to demonstrate how you can perform a deep filter in a child array without the necessity of a custom filter. Controller: View: Check the complete DEMO (opens new window). |
| Using filters in a controller or service By injecting |
| Your First Filter Filters are a special type of function that can modify how something is printed out to the page, or can be used to filter an array, or a For example, let's create a filter that will change a string to be all uppercase (essentially a wrapper of the Let's take a closer look at what's happening above. First, we're creating a filter called "toUppercase", which is just like a controller; Note: In this situation, we're assuming the object being passed into the filter is a string, and therefore know to always use the filter only on strings. That being said, a further improvement to the filter could be made that loops through the object (if it's an array) and then makes every element that is a string uppercase. Now let's use our new filter in action. Our filter can be used in two ways, either in an angular template or as a javascript function (as an injected Angular reference). JavascriptSimply inject the angular HTMLFor an angular directive, use the pipe ( Editor's Note: Angular has a number of built in filters, including "uppercase", and the "toUppercase" filter is intended only as a demo to easily show off how filters work, but you do not need to built your own uppercase function. |
Read Article
https://develop.horje.com/learn/1434/reference