Jordash
Jordash

Reputation: 3093

Format value from ng-model

When I output a variable like this I can format it to decimal places:

{{variable|number:2}}

How would I do the same thing in a text input?

<input type="text" ng-model="variable">

This doesn't work:

<input type="text" ng-model="variable|number:2">

Upvotes: 0

Views: 171

Answers (2)

faiyaz syed
faiyaz syed

Reputation: 44

//You can add watch in controller as well. Here is the sample

$scope.$watch('variable', function() {
        $scope.variable= "Here add your logic";
  });

Upvotes: 0

faiyaz syed
faiyaz syed

Reputation: 44

Filter are not allowed to use on ng-model.

Create directive and watch model value and update it upon change.

Upvotes: 1

Related Questions