Book Image

Ionic Cookbook

By : Hoc Phan
Book Image

Ionic Cookbook

By: Hoc Phan

Overview of this book

Table of Contents (18 chapters)
Ionic Cookbook
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a custom filter


Filters are a feature of AngularJS and not specific to Ionic. The main reason you might want to use a filter is when you just need the data to be displayed in a different format in the view. You don't want to change the actual value in the controller or factory. This makes things very convenient because you don't have to decide upon a specific format within the controller code while leaving the flexibility in the view component.

Here is the list of some out-of-the-box filters (from https://docs.angularjs.org/api/ng/filter):

  • currency

  • number

  • date

  • json

  • lowercase

  • uppercase

  • limitTo

  • orderBy

In this recipe, you will learn how to add more filters using the angular-filter module as well as create a custom filter. The following is the screenshot of the app:

Getting ready

There is no need to test in a physical device because the AngularJS filter will work just fine in a web browser.

How to do it...

Here are the instructions to create a custom filter:

  1. Create a new app using...