0

I have an input field that binds to product price which has 2 decimal precisions:

<input type="number" name="price" step=".01" id="price" ng-model="product.price" min="0" max="1000000" required>

I then ng-submit this product and get response from the server, updated the product.price from what's echo'ed from server, but the above price input becomes empty, now from

console.log($scope.product.price)

I can tell that this value from server is a string now, but then even if I do the follows:

$scope.product.price = parseFloat(response.updatedModel.price).toFixed(2);

the price input is still empty.... how can I make this price input show that price value in 2 decimal precisions echo'ed from server?

2
  • 1
    try removing .toFixed(2);: $scope.product.price = parseFloat(response.updatedModel.price); Commented Oct 11, 2014 at 13:49
  • Yes, you're right about that! Thanks bro! Commented Oct 11, 2014 at 13:53

1 Answer 1

4

The problem is your input requires the property to be a Number, but toFixed converts it to string.

Try removing .toFixed(2);:

$scope.product.price = parseFloat(response.updatedModel.price);

When working with model-view architecture, the model should not be concerned with how it's displayed, it's view's concern which is your input (step=".01") in your case.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.