0

Lets say, I'm having 5 text box which are created dynamically. All fields having default value that are coming from database and that are binded to input field.

<html>
<div data-ng-repeat="Input in InputArray">
    Input Field
    <label>{{$index + 1}} : </label>
    <input type="text" data-ng-model="Input.InputValue" data-ng-change="" />
</div>
<div>
    Calculated Result :    
    <label>{{CalculatedValue}}</label>
</div>
<div>
    <input type="button" name="Update Calculated Result to 3rd Input Field" data-ng-click="" />
</div>
</html>

I'm having label which have Calculated value. Its value is updated from another input field.

I want to update particular / only one text box value from that label value on a button click.

Is it possible to update by using ID of input field?

2
  • can you please create a fiddle for this ? Commented Sep 8, 2015 at 5:59
  • you can update InputArray in the 3rd place Commented Sep 8, 2015 at 6:04

1 Answer 1

0

You don't need any DOM manipulation. The input field is two-way bound to the model, so all you need to get the field value is to get the corresponding model value.

So, to get the third input field value, since it's bound to the InputValue field of the third Input object in InputArray, all you need is

$scope.CalculatedValue = $scope.InputArray[2].InputValue; 

Similarly, if you want to set the third field value with the value contained in CalculatedValue, all you need it

$scope.InputArray[2].InputValue = $scope.CalculatedValue;
Sign up to request clarification or add additional context in comments.

2 Comments

Is it possible to do something like this in button? <input type="button" ng-click="InputArray[2].InputValue = {{CalculatedValue}}" />
You have to remove the curly braces. But I would rather call a function of the scope, and put that code in the function.

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.