I've created an ng-bind
element in my template, which displays a number rounded by one decimal. How do I add a %
to the end of it, from within the ng-bind
logic?
My code:
<span ng-bind="variable | number: 1"
class="animated" ng-show="variable"
ng-class="{'fadeIn':variable}"></span>
Results in (for example) 4.5
but I want it to be 4.5%
.
The thing is, I want to add a %
-character to the end of it, but how? I'd rather not add a second span, with the exact same logic, just for that one character, and ng-bind="variable + '%' | number: 1"
is not working. I'd also like to avoid extra code in my controllers/directives, since I think this is more a template thing (and I only need to use it just a few times).
<span class="animated" ng-show="variable" ng-class="{'fadeIn':variable}">{{variable | number: 1}}%</span>
or create/use a percentage filter... or create a custom filter which does the just of rounding number and adding percentage.. How aboutng-bind="(variable | number: 1) + '%'"
– Pannierng-bind
or use interpolation... there is no overkill, both are almost virtually the same. using filters yes, if you dont need to do more complex stuffs on it. – Pannier