angularjs - Update the model and selected option of a select that is generated using ng-options -
unfortunately i'm going round in circle trying work out - appreciated.
i update model , selected option of select generated using ng-options.
here values options:
var blahoptionvalues = [ {valueformodel: '1', optiontext: 'a'}, {valueformodel: '2', optiontext: 'b'}, {valueformodel: '3', optiontext: 'c'}, ]
here view:
<select ng-model="blahmodel" ng-options="item.valueformodel item.optiontext item in blahoptionvalues"></select>
as result of event, how update "blahmodel" relevant value? update selected value in view well?
yes, update view well. please check demo in plunker: link: http://plnkr.co/edit/7xvrn7gmfkrjs7e4fvuh?p=preview`
var app = angular.module('myapp', []); app.controller('myctrl', function($scope) { $scope.blahoptionvalues = [ {valueformodel: '1', optiontext: 'a'}, {valueformodel: '2', optiontext: 'b'}, {valueformodel: '3', optiontext: 'c'}, ]; $scope.blahmodel = '2'; $scope.update = function(){ $scope.blahmodel = '1'; }; });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="myapp" ng-controller="myctrl">{{blahmodel}} <select ng-model="blahmodel" ng-options="item.valueformodel item.optiontext item in blahoptionvalues"></select> <button ng-click="update()" >update</button> </div>
`
Comments
Post a Comment