// In app.js or main.js or whatever: | |
// var myApp = angular.module('askchisne', ['ngSanitize', 'ngAnimate', 'ui.bootstrap', 'ui.bootstrap.tpls']); | |
// This filter makes the assumption that the input will be in decimal form (i.e. 17% is 0.17). | |
myApp.filter('percentage', ['$filter', function ($filter) { | |
return function (input, decimals) { | |
return $filter('number')(input * 100, decimals) + '%'; | |
}; | |
}]); | |
// Usage: | |
<tr ng-repeat="i in items"> | |
<td>{{i.statistic | percentage:2}}</td> | |
</tr> |
This comment has been minimized.
This comment has been minimized.
Thank You. Worked just fine! |
This comment has been minimized.
This comment has been minimized.
Awesome! just what I needed. saved me time. |
This comment has been minimized.
This comment has been minimized.
nice, but i suggest a more 'built-in' approach: |
This comment has been minimized.
This comment has been minimized.
Awesome post |
This comment has been minimized.
This comment has been minimized.
Thanks! |
This comment has been minimized.
This comment has been minimized.
Any way you could update this to hide the decimal zero? |
This comment has been minimized.
This comment has been minimized.
Works great! |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
Thanks! |
This comment has been minimized.
This comment has been minimized.
If I wanted to put this inline as in: cellFilter: $filter(''number')(input * 100, decimals) + '%'; ... if I put it inline, what would I put instead of 'input'? I am getting an error this way, & trying to inject the custom filter is not working for me right now for some reason. |
This comment has been minimized.
This comment has been minimized.
thanks for sharing this. |
This comment has been minimized.
This comment has been minimized.
thanks for working example |
This comment has been minimized.
This comment has been minimized.
@jeffjohnson9046 In my project I have the same code what you have posted above , I confused on the I dont get any Clue where they assigned input value ? Please guide me. |
This comment has been minimized.
This comment has been minimized.
Thanks! |
This comment has been minimized.
This comment has been minimized.
thanks! |
This comment has been minimized.
This comment has been minimized.
Thanks for this. |
This comment has been minimized.
This comment has been minimized.
Awesome! How do you apply this to an input tag though? I only need to put a '%' suffix in the input but read the numeric value in the model? |
This comment has been minimized.
This comment has been minimized.
Thank you! |
This comment has been minimized.
This comment has been minimized.
Works like charm... |
This comment has been minimized.
This comment has been minimized.
i need to add decimal point with dot (.) or comma (,) separator.how could anyone find a way to solve the problem. |
This comment has been minimized.
This comment has been minimized.
Useful, thanks! |
This comment has been minimized.
This comment has been minimized.
Awesome, thanks! |
This comment has been minimized.
This comment has been minimized.
Thanks |
This comment has been minimized.
This comment has been minimized.
@LahiruDhananjaya, you only have to use i18n and l10n. |
This comment has been minimized.
This comment has been minimized.
nice.
|
This comment has been minimized.
This comment has been minimized.
This solution taught me what i need to know about pipes AKA filters. Jeez!! |
This comment has been minimized.
works like a charm! thank you.