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

Commit aeefb7c

Browse files
IgorMinargkalpak
authored andcommitted
step-11 Custom Filters
- Implement a custom `checkmark` filter. - Update the `phoneDetail` template to use the `checkmark` filter. - Add a unit test for the `checkmark` filter.
1 parent 4b67b04 commit aeefb7c

File tree

6 files changed

+35
-5
lines changed

6 files changed

+35
-5
lines changed

app/app.module.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Define the `phonecatApp` module
44
angular.module('phonecatApp', [
55
'ngRoute',
6+
'core',
67
'phoneDetail',
78
'phoneList'
89
]);
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
angular.
4+
module('core').
5+
filter('checkmark', function() {
6+
return function(input) {
7+
return input ? '\u2713' : '\u2718';
8+
};
9+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
describe('checkmark', function() {
4+
5+
beforeEach(module('core'));
6+
7+
it('should convert boolean values to unicode checkmark or cross',
8+
inject(function(checkmarkFilter) {
9+
expect(checkmarkFilter(true)).toBe('\u2713');
10+
expect(checkmarkFilter(false)).toBe('\u2718');
11+
})
12+
);
13+
14+
});

app/core/core.module.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'use strict';
2+
3+
// Define the `core` module
4+
angular.module('core', []);

app/index.html

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
<script src="bower_components/angular-route/angular-route.js"></script>
1010
<script src="app.module.js"></script>
1111
<script src="app.config.js"></script>
12+
<script src="core/core.module.js"></script>
13+
<script src="core/checkmark/checkmark.filter.js"></script>
1214
<script src="phone-list/phone-list.module.js"></script>
1315
<script src="phone-list/phone-list.component.js"></script>
1416
<script src="phone-detail/phone-detail.module.js"></script>

app/phone-detail/phone-detail.template.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ <h1>{{$ctrl.phone.name}}</h1>
4848
<dt>Bluetooth</dt>
4949
<dd>{{$ctrl.phone.connectivity.bluetooth}}</dd>
5050
<dt>Infrared</dt>
51-
<dd>{{$ctrl.phone.connectivity.infrared}}</dd>
51+
<dd>{{$ctrl.phone.connectivity.infrared | checkmark}}</dd>
5252
<dt>GPS</dt>
53-
<dd>{{$ctrl.phone.connectivity.gps}}</dd>
53+
<dd>{{$ctrl.phone.connectivity.gps | checkmark}}</dd>
5454
</dl>
5555
</li>
5656
<li>
@@ -79,7 +79,7 @@ <h1>{{$ctrl.phone.name}}</h1>
7979
<dt>Screen resolution</dt>
8080
<dd>{{$ctrl.phone.display.screenResolution}}</dd>
8181
<dt>Touch screen</dt>
82-
<dd>{{$ctrl.phone.display.touchScreen}}</dd>
82+
<dd>{{$ctrl.phone.display.touchScreen | checkmark}}</dd>
8383
</dl>
8484
</li>
8585
<li>
@@ -92,9 +92,9 @@ <h1>{{$ctrl.phone.name}}</h1>
9292
<dt>Audio / headphone jack</dt>
9393
<dd>{{$ctrl.phone.hardware.audioJack}}</dd>
9494
<dt>FM Radio</dt>
95-
<dd>{{$ctrl.phone.hardware.fmRadio}}</dd>
95+
<dd>{{$ctrl.phone.hardware.fmRadio | checkmark}}</dd>
9696
<dt>Accelerometer</dt>
97-
<dd>{{$ctrl.phone.hardware.accelerometer}}</dd>
97+
<dd>{{$ctrl.phone.hardware.accelerometer | checkmark}}</dd>
9898
</dl>
9999
</li>
100100
<li>

0 commit comments

Comments
 (0)