Angularjs ng选项和更新模型
在下面的场景中,当选择客户机时,我希望在gallery模型中进行更新。如何使用选定的客户端更新库模型Angularjs ng选项和更新模型,angularjs,ng-options,Angularjs,Ng Options,在下面的场景中,当选择客户机时,我希望在gallery模型中进行更新。如何使用选定的客户端更新库模型 <form novalidate> <div class="control-group"> <label for="galleryName">Gallery Name:</label> <input value="{{gallery.galleryName
<form novalidate>
<div class="control-group">
<label for="galleryName">Gallery Name:</label>
<input value="{{gallery.galleryName}}" id="galleryName" type="text" ng-model="gallery.galleryName">
<p>{{gallery}}</p>
</div><!-- /control-group -->
<div class="control-group">
<label for="clientName">Client Name:</label>
<select name="client" ng-model="clientList" ng-options="client.id as client.clientName for client in clients" >
<option value="">Choose Client</option>
</select>
{{clientList}}
</div>
</form>
我的目标是在更改客户端列表时更改“客户端”。您可以使用
$scope.$watch
,您可以这样做
$scope.$watch('clientList', function (oldValue, newValue) {
$scope.gallery.client = newValue; //newValue is the client.id
});
顺便说一句,您应该将
clientList
重命名为其他名称,因为您选择的只是一个项。理解,使用$scope.$watch,这是否最好放在指令中?对于您的实现,请将其放在controller中。感谢您在这方面的帮助。这在这个问题上有点令人毛骨悚然,但在这个实现上却让我绞尽脑汁。我需要访问此promise$scope.galleryCollection.then中的scope.gallery(函数(库){$scope.gallery=gallers.thisGal;});,还没有弄明白。您按照v1.3交换了旧值和新值
$scope.$watch('clientList', function (oldValue, newValue) {
$scope.gallery.client = newValue; //newValue is the client.id
});