1

I need to apply angular's filter number to input value directly.

I thought the code below must work, but it doesn't..

<input type="text" ng-model="product.price" value="{{product.price | number}}" required>

Is it possible to implement this by default Angular resources? Without writting directives?

2
  • use ng-pattern for this.. Commented May 14, 2015 at 5:34
  • ng-patter is more for validation purposes I guess? Commented May 14, 2015 at 5:43

2 Answers 2

2

This can be achived using regex or ng-pattern.

<input type="text" ng-model="product.price" ng-pattern="/^(\d)+$/" required>

2.If you want to format the data value, you can do something like this.

$scope.product.price= parseInt($scope.product.price)
Sign up to request clarification or add additional context in comments.

2 Comments

It must format the input value like Angular's filter number. Your code doesn't do this..
if you want to format your data value to number, do this in controller itself.
1

You don't need to use the value attribute when you have the ng-model attribute:

<input type="text" ng-model="product.price" required>

Set the value of product.price in the controller. If you want to format the price, do it in the controller as well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.