erp erp - 1 year ago 91
AngularJS Question

Display input as precentage

I have a html slider and an input field that sits right next to it. The input field displays the same value as the slider .01 - .99. I am wondering how to display the number in the input field as a percentage version of it, ie .99 is displayed as 99%. The code is simple but here:

<div sc-slider
<input type="text"

If you can link me to something else on line cool but I looked and couldn't find anything and surely can't be the only person needing to do this. I tried to do like
vm.baseline *100
but for obvious reasons that didn't work. Help if you can!

Answer Source

You can implement custom directive that require: ngModel and change input/output with $parsers | $formatters

Here is a plunker:

app.directive('toPercent', function(){
  return {
    require: 'ngModel',
    link: function(scope, element, attrs, ngModelCtrl){
          return value * 100 + '%';

          return parseFloat(value.replace('%', ''));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download