Beginning AngularJS

(WallPaper) #1
Chapter 4 ■ Filters and Modules

medium: {{ data.dateJoined | date:'medium'}}


mediumDate: {{ data.dateJoined | date:'mediumDate'}}


shortDate: {{ data.dateJoined | date:'shortDate'}}


This customer joined in the month of {{ data.dateJoined | date:'MMMM'}} on a {{
data.dateJoined | date:'EEEE'}} at {{ data.dateJoined | date:'ha'}}




In most cases, the predefined date parameters more than fit the bill; though the last paragraph shows that you
can also take a more granular approach. You can see the results in Figure 4-4.


Figure 4-4. Date filter parameters in action


Notice that to produce the month and the day, we use 'MMMM' and 'EEEE', respectively, which both appear in
Table 4-1. You will not, however, see 'ha', as used to produce the time portion (12AM) in Table 4-1. You will see an 'h'
and an 'a', the former being the hour, and the latter being the AM/PM marker. It is perfectly acceptable, and often
necessary, to combine date parameters in this manner.


The limitTo Filter

We will finish up on the built-in filters with a look at the limitTo filter. This handy filter lets you limit the amount of
information displayed from an array. It does this by creating a new array, which contains a subset of the items that are
contained in the original array. To showcase the usefulness of this filter, we will add a new property to our sample data
source. This new property will contain the customer’s historical data usage for the last 12 months. Listing 4-6 is the
controller, revised to show this new property.

Free download pdf