无法更新AngularJs中的Select值 [英] Unable to update value of Select from AngularJs
本文介绍了无法更新AngularJs中的Select值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法更新AngularJs中的select值。
I am unable to update value of select from AngularJs.
这是我的代码
<select ng-model="family.grade" >
<option ng-repeat="option in options" value='{{option.id}}'>{{option.text}}</option>
</select>
以下是我用来填充选择的选项
Here are the options which i am using to populate my select
var options = [{text:'Pre-K',id:'Pre-K'},
{text:'K',id:'K'},
{text:'1',id:'1'},
{text:'2',id:'2'},
{text:'3',id:'3'},
{text:'4',id:'4'},
{text:'5',id:'5'},
{text:'6',id:'6'},
{text:'7',id:'7'},
{text:'8',id:'8'},
{text:'+',id:'+'}];
这是mu js代码。
Here is mu js code.
$scope.$watch("family_member.date_of_birth" ,function(newValue, oldValue){
$scope.family.grade = "1"
})
当family_member.date_of_birth的值发生变化时它应该将select的值设置为1.但是此更改在UI上不可见。
When ever value of family_member.date_of_birth changes it should set they value of select to 1. But this change is not visible on UI.
推荐答案
您应该使用ngSelected来选择选项。
You should use ngSelected to select the option.
它可能是这样的:
<select ng-model="family.grade" >
<option ng-repeat="option in options"
value='{{option.id}}' ng-selected="family.grade==option.id">
{{option.text}}</option>
</select>
希望这会有所帮助。
这篇关于无法更新AngularJs中的Select值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文