angularjs - ng-options and updating model -


under following scenario, when client selected, update in gallery model. how update gallery model selected client?

<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 client.clientname client in clients" >                     <option value="">choose client</option>                 </select>                 {{clientlist}}             </div>         </form> 

example of gallery model:

{"id":"57","galleryname":"sam","clientref":"205","client":"245","favorited":"1","timestamp":"1374524146"} 

my goal change "client" when clientlist changed.

you can use $scope.$watch, , this

$scope.$watch('clientlist', function (oldvalue, newvalue) {     $scope.gallery.client = newvalue; //newvalue client.id }); 

btw, should rename clientlist else, since select one item.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -