Book Image

Data Oriented Development with Angularjs

Book Image

Data Oriented Development with Angularjs

Overview of this book

Table of Contents (17 chapters)
Data-oriented Development with AngularJS
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Filters


It often happens that we need to show filtered data. In this case, we can include logic in one of the functions in a service. However, this logic can get lost if a service has many methods. Similarly, we might have to format some data before showing it in the view. Angular introduces filters for precisely these things—either format the value of an expression for display or filter values from an array. Angular comes with some of the most common filters to format number, currency, or date. Refer to the built-in filters available at https://docs.angularjs.org/api/ng/filter.

Let's write a custom filter. In our previous example, our service returns some employees. Let's add a few more employees whose age is more than 58 years. Let's assume that the retirement age is 60 years, and anyone whose age is 58 years or more is about to retire. Then, let's filter the employees. So, here's the modified service:

'use strict';

app.service('employeeSvc', function () {

  var Employee = function (name...