Created
May 20, 2016 09:25
-
-
Save cpoDesign/d1ccb5320b2229b41181a55818d475db to your computer and use it in GitHub Desktop.
Angular JS - custom date format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = angular.module('angularjs-starter', []); | |
app.filter('customCurrency', ["$filter", function ($filter) { | |
return function(amount, currencySymbol){ | |
var currency = $filter('currency'); | |
if(amount<0){ | |
return '-' + currency(amount, currencySymbol).replace('(','').replace(')',''); | |
} | |
return currency(amount, currencySymbol); | |
}; | |
}]); | |
app.controller('MainCtrl', function($scope) { | |
$scope.amount = -250.75; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html ng-app="angularjs-starter"> | |
<head lang="en"> | |
<meta charset="utf-8"> | |
<title>Custom Plunker</title> | |
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js"></script> | |
<link rel="stylesheet" href="style.css"> | |
<script> | |
document.write('<base href="' + document.location + '" />'); | |
</script> | |
<script src="app.js"></script> | |
</head> | |
<body ng-controller="MainCtrl"> | |
<h1>{{10 | currency}}</h1> | |
<h1>{{-10 | currency}}</h1> | |
<h1>{{-10 | currency:"£"}}</h1> | |
<p>{{amount | currency:"£"}}</p> | |
<p>{{amount | customCurrency:"£"}}</p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment