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

Commit

Permalink
step-11 Custom Filters
Browse files Browse the repository at this point in the history
- Implement a custom `checkmark` filter.
- Update the `phoneDetail` template to use the `checkmark` filter.
- Add a unit test for the `checkmark` filter.
  • Loading branch information
IgorMinar authored and gkalpak committed Nov 21, 2016
1 parent 4b67b04 commit aeefb7c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/app.module.js
Expand Up @@ -3,6 +3,7 @@
// Define the `phonecatApp` module
angular.module('phonecatApp', [
'ngRoute',
'core',
'phoneDetail',
'phoneList'
]);
9 changes: 9 additions & 0 deletions app/core/checkmark/checkmark.filter.js
@@ -0,0 +1,9 @@
'use strict';

angular.
module('core').
filter('checkmark', function() {
return function(input) {
return input ? '\u2713' : '\u2718';
};
});
14 changes: 14 additions & 0 deletions app/core/checkmark/checkmark.filter.spec.js
@@ -0,0 +1,14 @@
'use strict';

describe('checkmark', function() {

beforeEach(module('core'));

it('should convert boolean values to unicode checkmark or cross',
inject(function(checkmarkFilter) {
expect(checkmarkFilter(true)).toBe('\u2713');
expect(checkmarkFilter(false)).toBe('\u2718');
})
);

});
4 changes: 4 additions & 0 deletions app/core/core.module.js
@@ -0,0 +1,4 @@
'use strict';

// Define the `core` module
angular.module('core', []);
2 changes: 2 additions & 0 deletions app/index.html
Expand Up @@ -9,6 +9,8 @@
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="app.module.js"></script>
<script src="app.config.js"></script>
<script src="core/core.module.js"></script>
<script src="core/checkmark/checkmark.filter.js"></script>
<script src="phone-list/phone-list.module.js"></script>
<script src="phone-list/phone-list.component.js"></script>
<script src="phone-detail/phone-detail.module.js"></script>
Expand Down
10 changes: 5 additions & 5 deletions app/phone-detail/phone-detail.template.html
Expand Up @@ -48,9 +48,9 @@ <h1>{{$ctrl.phone.name}}</h1>
<dt>Bluetooth</dt>
<dd>{{$ctrl.phone.connectivity.bluetooth}}</dd>
<dt>Infrared</dt>
<dd>{{$ctrl.phone.connectivity.infrared}}</dd>
<dd>{{$ctrl.phone.connectivity.infrared | checkmark}}</dd>
<dt>GPS</dt>
<dd>{{$ctrl.phone.connectivity.gps}}</dd>
<dd>{{$ctrl.phone.connectivity.gps | checkmark}}</dd>
</dl>
</li>
<li>
Expand Down Expand Up @@ -79,7 +79,7 @@ <h1>{{$ctrl.phone.name}}</h1>
<dt>Screen resolution</dt>
<dd>{{$ctrl.phone.display.screenResolution}}</dd>
<dt>Touch screen</dt>
<dd>{{$ctrl.phone.display.touchScreen}}</dd>
<dd>{{$ctrl.phone.display.touchScreen | checkmark}}</dd>
</dl>
</li>
<li>
Expand All @@ -92,9 +92,9 @@ <h1>{{$ctrl.phone.name}}</h1>
<dt>Audio / headphone jack</dt>
<dd>{{$ctrl.phone.hardware.audioJack}}</dd>
<dt>FM Radio</dt>
<dd>{{$ctrl.phone.hardware.fmRadio}}</dd>
<dd>{{$ctrl.phone.hardware.fmRadio | checkmark}}</dd>
<dt>Accelerometer</dt>
<dd>{{$ctrl.phone.hardware.accelerometer}}</dd>
<dd>{{$ctrl.phone.hardware.accelerometer | checkmark}}</dd>
</dl>
</li>
<li>
Expand Down

0 comments on commit aeefb7c

Please sign in to comment.