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

Commit 42b5ce9

Browse files
committed
docs(guide/filter): clarify how to use filters in controllers
Closes #11915
1 parent 2cb1989 commit 42b5ce9

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

docs/content/guide/filter.ngdoc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ E.g. the markup `{{ 1234 | number:2 }}` formats the number 1234 with 2 decimal p
3232

3333
## Using filters in controllers, services, and directives
3434

35-
You can also use filters in controllers, services, and directives. For this, inject a dependency
36-
with the name `<filterName>Filter` to your controller/service/directive. E.g. using the dependency
37-
`numberFilter` will inject the number filter. The injected argument is a function that takes the
38-
value to format as first argument and filter parameters starting with the second argument.
35+
You can also use filters in controllers, services, and directives.
36+
37+
<div class="alert alert-info">
38+
For this, inject a dependency with the name `<filterName>Filter` into your controller/service/directive.
39+
E.g. a filter called `number` is injected by using the dependency `numberFilter`. The injected argument
40+
is a function that takes the value to format as first argument, and filter parameters starting with the second argument.
41+
</div>
3942

4043
The example below uses the filter called {@link ng.filter:filter `filter`}.
4144
This filter reduces arrays into sub arrays based on
@@ -108,6 +111,7 @@ text upper-case.
108111
No filter: {{greeting}}<br>
109112
Reverse: {{greeting|reverse}}<br>
110113
Reverse + uppercase: {{greeting|reverse:true}}<br>
114+
Reverse, filtered in controller: {{filteredGreeting}}<br>
111115
</div>
112116
</file>
113117

@@ -127,8 +131,9 @@ text upper-case.
127131
return out;
128132
};
129133
})
130-
.controller('MyController', ['$scope', function($scope) {
134+
.controller('MyController', ['$scope', 'reverseFilter', function($scope, reverseFilter) {
131135
$scope.greeting = 'hello';
136+
$scope.filteredGreeting = reverseFilter($scope.greeting);
132137
}]);
133138
</file>
134139
</example>

0 commit comments

Comments
 (0)