html - How to set the value property in AngularJS -
html code
<select class="form-control" id="txtcity" data-ng-model="register.city" ng-options="item item in dtcmbcity"> <option value="">please select</option> </select> <button type="button" ng-click="btnset();">set item</button>
js code
$scope.register = {city: ''}; $scope.dtcmbcity = ['delhi','bombay','chennai']; $scope.btnset= function () { $scope.register.city = "delhi" }
my problem when load form data (delhi,bombay,chennai) displayed in select box. , click set button want set delhi selection box.
thanks please help
if looking setting value attribute in options fields same text value can you.
your current code .
ng-options="item item in dtcmbcity"
result html.
<select class="form-control ng-pristine ng-valid ng-touched" id="txtcity" data-ng-model="register.city" ng-options="item item in dtcmbcity"> <option value="" class="" selected="selected">please select</option> <option label="delhi" value="string:delhi">delhi</option> <option label="bombay" value="string:bombay">bombay</option> <option label="chennai" value="string:chennai">chennai</option> </select>
if use track in ng-options , html code is
ng-options="item item in dtcmbcity track item"
result html.
<select class="form-control ng-pristine ng-valid ng-touched" id="txtcity" data-ng-model="register.city" ng-options="item item in dtcmbcity track item"> <option value="" class="" selected="selected">please select</option> <option label="delhi" value="delhi">delhi</option> <option label="bombay" value="bombay">bombay</option> <option label="chennai" value="chennai">chennai</option> </select>
setting value on button click working fine.
Comments
Post a Comment