0

I have an array like this:

var data = [{
    "chamberName": "Community App",
    "representativeEmail": "[email protected]",
    "primaryColor": "#325490",
}]

And an input on a form like this:

<input type="text" class="form-control" id="chamberName" ng-change="" placeholder="Chamber Name">

I'd like to use ng-change to change the array value that matches the changing input value. I can't figure out how to get the input value though. I am thinking something like:

ng-change="data[0].chamberName = inputValue";

Any help would be great!

SIDE NOTE: You need to use $parent when using ng-include.

2
  • I think you're looking for ngModel not ngChange. Commented Aug 16, 2016 at 14:22
  • You want to create binding ? Commented Aug 16, 2016 at 14:23

1 Answer 1

1

You need to use ngModel.

Why your original data in array?

If you need to edit only one instance it is simpler to use object and pass object's property to ngModel

<input .. data-ng-model="data.chamberName" .. />

Or if you are going to edit pool of objects, than you can surround it with ngRepeat

<fieldset data-ng-repeat="elm in data">
  <input .. data-ng-model="elm.chamberName" .. />
  ..
</fieldset>

Or if you still want to store your single object in array

<input .. data-ng-model="data[0].chamberName" .. />
Sign up to request clarification or add additional context in comments.

3 Comments

Do you have an example of ng-model?
What do you mean? I've wrote you three examples.
I got it now. I didn't understand that the ng-model="data[0].chamberName" was a binding type deal.

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.