Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I am new to AngularJS, and I have a problem with ng-model.

Here's my code:

<section class="field row" ng-repeat="field in fields">
    <input class="value" ng-show="editMode" placeholder="{{field.name}}" ng-model="field.value" type="url" />   
</section> 

As you can see, I'm looping through $scope.fields which I got from the server and is an array of about 40 objects that have keys like name and value.

Inside the section I have an input, which has the ng-model property set to field.value. When the server gives a value to the field, it is shown inside the input. At some point I want to update the user's changes, by sending $scope.fields back to the server.

However, when the user changes something in the inputs, the value for the changes fields becomes undefined.

I hope this describes my problem well enough.

Thanks!

share|improve this question

To get the changes, you should pass the original object name i.e fields. Refer below calling fn ng-click="save(fields)"

share|improve this answer
up vote 0 down vote accepted

The reason this caused a problem is simply because the input was a URL input and I was typing simple "hello" strings to test it, instead of typing URLS. Apparently AngulaeJS only puts the answer in the model if it matches the field type.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.