Reputation: 729
I have a form that's meant to let the user edit some information
My problem is with <input class="form-control" type="text" ng-repeat="info in item.Question" ng-model="info"/>
. When I click on the save button, the logs (example copied below) tell me it's not updating the model. Can anyone see why?
I read on a few other questions that ng-model needs an object.property value, but I don't see how i can apply that here
<div class="panel panel-primary" ng-show="item.edit">
<div class="panel-heading">
<h3 class="panel-title">
<form class="form-group form-inline">
<input class="form-control" type="text" ng-model="item.Name" />
<span class="badge pull-right">₤<input class="form-control" type="number" step="any" ng-model="item.Price" /></span>
</form>
</h3>
</div>
<div class="panel-body">
<input class="form-control" type="text" ng-model="item.Desc" />
<hr>
<div class="col-md-11">
<input class="form-control" type="text" ng-repeat="info in item.Question" ng-model="info"/>
</div>
<div class="col-md-1">
<a href="" ng-click="cat.newQuestion(item)" class="btn btn-success"><span class="glyphicon glyphicon-plus"></span></a>
</div>
</div>
<div class="panel-footer">
<div class="btn-group">
<a href="" ng-click="cat.change(item)" class="btn btn-success">Save</a>
<a href="" ng-click="item.edit = false" class="btn btn-primary">Cancel</a>
<a href="" ng-click="cat.deleteItem(item)" class="btn btn-danger">Delete</a>
</div>
</div>
</div>
an example of the log from the change()
function:
app.js:39 Object {ID: "10", Name: "New User", Price: 0, Desc: "Create a new user for the Quarriers network", CatID: "3"…}$$hashKey: "object:50"CatID: "3"Desc: "Create a new user for the Quarriers network"ID: "10"Name: "New User"Price: 0Question: "username,"edit: true
app.js:40 stringing
app.js:46 Object {ID: "10", Name: "New User", Price: 0, Desc: "Create a new user for the Quarriers network", CatID: "3"…}$$hashKey: "object:50"CatID: "3"Desc: "Create a new user for the Quarriers network"ID: "10"Name: "New User"Price: 0Question: "username,"edit: true__proto__: Object
Upvotes: 0
Views: 53
Reputation: 38490
If you don't want to change Question
to an object with a property you can use the following:
<input ng-repeat="info in item.Question track by $index" ng-model="item.Question[$index]"/>
Upvotes: 1