@@ -32,10 +32,13 @@ E.g. the markup `{{ 1234 | number:2 }}` formats the number 1234 with 2 decimal p
32
32
33
33
## Using filters in controllers, services, and directives
34
34
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>
39
42
40
43
The example below uses the filter called {@link ng.filter:filter `filter`}.
41
44
This filter reduces arrays into sub arrays based on
@@ -108,6 +111,7 @@ text upper-case.
108
111
No filter: {{greeting}}<br>
109
112
Reverse: {{greeting|reverse}}<br>
110
113
Reverse + uppercase: {{greeting|reverse:true}}<br>
114
+ Reverse, filtered in controller: {{filteredGreeting}}<br>
111
115
</div>
112
116
</file>
113
117
@@ -127,8 +131,9 @@ text upper-case.
127
131
return out;
128
132
};
129
133
})
130
- .controller('MyController', ['$scope', function($scope) {
134
+ .controller('MyController', ['$scope', 'reverseFilter', function($scope, reverseFilter ) {
131
135
$scope.greeting = 'hello';
136
+ $scope.filteredGreeting = reverseFilter($scope.greeting);
132
137
}]);
133
138
</file>
134
139
</example>
0 commit comments