0
<input id="width" name="width" style="width:100px" value="550" type="text" ng-model="width">

How would I get the value from above to write into the $scope under $scope.user.width ?

Whilst keeping the initial value="500"

1 Answer 1

3

Initialise the value in your controller:

$scope.user = {width : 500};
<input id="width" name="width" type="text" ng-model="user.width">
Sign up to request clarification or add additional context in comments.

4 Comments

$scope.user.width would update with the value when the input field value has changed?
Of course! That's the goal of the ngModel directive.
Does $scope.user.width or $scope.user = {width: ''}; need to be set in order for <input id="width" name="width" type="text" ng-model="user.width"> to store the values?
@Donald It will be set automatically when the input value is changed if not defined previously, if this is your question.

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.