Size conversion filter using AngularJS


Following code should give you a clean and simple example of custom filter using AngularJS.

HTML code:
———————

<!doctype html>
<html >
<head>
<script src=”src=”http://code.angularjs.org/angular-1.0.0rc6.min.js”></script >
<script src=”filter.js“></script>
</head>
<body>
<div ng-app=”testFilterApp“>
<label>Size in Byte:</label>
<input type=”text” ng-model=”sizeInB” placeholder=”Enter a name here”>
<hr>
<h2>Human Readable Size (precision:3) {{sizeInB | sizeConverter:3}}!</h2>
<h2>Human Readable Size (precision: not defined) {{sizeInB | sizeConverter}}!</h2>
</div>
</body>
</html>

Continue reading

Advertisements