Filters are extremely helpful tools for formatting data directly in the HTML view.
They transform data right before it renders, without altering the original model!
Filters can convert text to uppercase, format numbers as currency, or sort an array.
You apply a filter to an expression using the pipe character |.
AngularJS comes with numerous built-in filters, saving you from writing formatting functions.
uppercase: Formats a string to all uppercase letters.currency: Formats a number as a currency value (like $10.00).orderBy: Sorts an array based on an object property.
<div ng-app="myApp" ng-controller="myCtrl">
<p>Name in Uppercase: {{ name | uppercase }}</p>
<p>Price Formatting: {{ price | currency }}</p>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.name = "John Doe";
$scope.price = 50;
});
</script>
Rendering data clearly and cleanly enhances user experience drastically.
Properly formatted currency and readable text signal high-quality content to search engines.
Use filters to easily display dynamic data in a polished, professional manner.
Which character is used to attach a filter to an AngularJS expression?