Angularjs

Angular JS Filters

Filters can be added to directives and expressions using a Pipe in Angular JS.

Currency:

Currency filter formats a number to a currency format.

Example:
Index.html:


 <div ng-app="" ng-controller="MyController2">
    <p>Total = {{ (test.quantity * test.price) | currency }}</p>
</div>

Script.JS file:

var MyController2 = function($scope)
{
 var test =
{
 quantity: 3,
 price: 2.5
};
$scope.test=test;
};

Output:

<span style="font-size: large;">Total = $7.50</span>

Using Filters in Angular JS:

A filter can be added to expression using a pipe.

Example:

 &lt;div ng-controller="MyController1"&gt;
      &lt;div&gt;First name: {{person.firstname|uppercase}}&lt;/div&gt;
      &lt;div&gt;Last name: {{person.lastname|uppercase}}&lt;/div&gt;
      &lt;div&gt;welcome {{person.firstname}} {{person.lastname}} &lt;/div&gt;
    &lt;/div&gt;

Output:

First name: TECH
Last name: KATAK
welcome Tech Katak
 

 

© 2015, www.techkatak.com. All rights reserved.