OLD | NEW |
| (Empty) |
1 part of angular.core; | |
2 | |
3 /** | |
4 * Use @[NgFilter] annotation to register a new filter. A filter is a class | |
5 * with a [call] method (a callable function). | |
6 * | |
7 * Usage: | |
8 * | |
9 * // Declaration | |
10 * @NgFilter(name:'myFilter') | |
11 * class MyFilter { | |
12 * call(valueToFilter, optArg1, optArg2) { | |
13 * return ...; | |
14 * } | |
15 * } | |
16 * | |
17 * | |
18 * // Registration | |
19 * var module = ...; | |
20 * module.type(MyFilter); | |
21 * | |
22 * | |
23 * <!-- Usage --> | |
24 * <span>{{something | myFilter:arg1:arg2}}</span> | |
25 */ | |
26 class NgFilter { | |
27 final String name; | |
28 | |
29 const NgFilter({this.name}); | |
30 | |
31 int get hashCode => name.hashCode; | |
32 bool operator==(other) => this.name == other.name; | |
33 | |
34 toString() => 'NgFilter: $name'; | |
35 } | |
36 | |
37 /** | |
38 * Registry of filters at runtime. | |
39 */ | |
40 @NgInjectableService() | |
41 class FilterMap extends AnnotationMap<NgFilter> { | |
42 Injector _injector; | |
43 FilterMap(Injector injector, MetadataExtractor extractMetadata) : | |
44 this._injector = injector, | |
45 super(injector, extractMetadata); | |
46 | |
47 call(String name) { | |
48 var filter = new NgFilter(name:name); | |
49 var filterType = this[filter]; | |
50 return _injector.get(filterType); | |
51 } | |
52 } | |
53 | |
OLD | NEW |