我有一个表单,旨在让用户编辑一些信息
我的问题是 <input class="form-control" type="text" ng-repeat="info in item.Question" ng-model="info"/>
。当我单击“保存”按钮时,日志(下面复制的示例)告诉我它没有更新模型。谁能明白为什么吗?
我读到了其他一些问题,说 ng-model 需要一个 object.property 值,但我不知道如何在这里应用它
<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>
来自 change()
的日志示例功能:
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
最佳答案
如果您不想将 Question
更改为具有属性的对象,您可以使用以下内容:
<input ng-repeat="info in item.Question track by $index" ng-model="item.Question[$index]"/>
关于javascript - ng-model 不更新对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37587567/