2

I have the following, and I'm sure there's some simple solution here that I'm just overlooking. I'm loading data into the model, but it's not updating the input field.

<div ng-app>
  <h2>Testing</h2>
  <div ng-controller="MyCtrl">
  From: <input name="Price" type="number" ng-model='object.number["From"]' /> 
  To: <input name="Price" type="number" ng-model='object.number["To"]' />
  </div>
</div>

And JavaScript:

function MyCtrl($scope) {
    $scope.object = {number : {}};
    $scope.object['number'] = {From: null, To: null}
    console.log($scope.object['number']);

    $scope.loadPrice = function(){
        $scope.object['number'].From = "5";   
        $scope.object['number'].To = "5";   
    }

    $scope.loadPrice();
    console.log($scope.object['number'])

}

Included the fiddle:

http://jsfiddle.net/pCnfH/6/

1
  • Do you get any errors? Commented Jan 15, 2014 at 22:54

1 Answer 1

5

You're constraining the input to be of type="number" but setting the value to a string: $scope.object['number'].To = "5";

So you either want to set the values to numbers:

$scope.object['number'].From = 5;   
$scope.object['number'].To = 5;   

updated fiddle

Or remove the number constraint: that fiddle

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

1 Comment

Thanks. Quite an oversight on my part.

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.