AngularJS Essentials
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Data Handling<br />
Now, the output will be R$10.00, which is the same as the previous output but<br />
prefixed with a different symbol. Although it seems right to apply just the currency<br />
symbol, and in this case the Brazilian Real (R$), this doesn't change the usage of the<br />
specific decimals and group separators.<br />
In order to achieve the correct output, in this case R$10,00 instead of R$10.00,<br />
we need to configure the Brazilian (PT-BR) locale available inside the <strong>AngularJS</strong><br />
distribution package. In this package, we might find locales for most countries, and<br />
we just need to import these locales to our application in the following manner:<br />
<br />
After importing the locale, we will not have to use the currency symbol anymore<br />
because it's already wrapped inside.<br />
Besides the currency, the locale also defines the configuration of many other<br />
variables, such as the days of the week and months, which is very useful when<br />
combined with the next filter used to format dates.<br />
date<br />
The date filter is one of the most useful filters of the framework. Generally, a date<br />
value comes from the database or any other source in a raw and generic format.<br />
Because of this, such filters are essential to any kind of application.<br />
Basically, we can use this filter by declaring it inside any expression. In the following<br />
example, we have used the filter on a date variable attached to the scope:<br />
{{ car.entrance | date }}<br />
The output will be Dec 10, 2013. However, there are numerous combinations we<br />
can make with the optional format mask:<br />
{{ car.entrance | date:'MMMM dd/MM/yyyy HH:mm:ss' }}<br />
When you use this format, the output changes to December 10/12/2013 21:42:10.<br />
filter<br />
Have you ever tried to filter a list of data? This filter performs exactly this task, acting<br />
over an array and applying any filtering criteria.<br />
Now, let's include a field in our car parking application to search any parked cars<br />
and use this filter to do the job:<br />
index.html<br />