У меня есть форма, которая позволяет пользователю редактировать некоторую информацию
Моя проблема <input class="form-control" type="text" ng-repeat="info in item.Question" ng-model="info"/>
с <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]"/>
<div ng-repeat="info in item.Question"><input class="form-control" type="text" ng-model="info"/></div>