Javascript 选择“不自动更新使用ng repeat渲染的ng模型更改”
我正在指令中创建下拉列表,如下所示:Javascript 选择“不自动更新使用ng repeat渲染的ng模型更改”,javascript,angularjs,angularjs-directive,angularjs-scope,angularjs-ng-repeat,Javascript,Angularjs,Angularjs Directive,Angularjs Scope,Angularjs Ng Repeat,我正在指令中创建下拉列表,如下所示: <select ng-model="selectedSite"> <option value="new">Add New Site</option> <option value="line" disabled>------------------------</option> <option ng-repeat="site in defaultSites"
<select ng-model="selectedSite">
<option value="new">Add New Site</option>
<option value="line" disabled>------------------------</option>
<option ng-repeat="site in defaultSites"
value="{{$index}}">
{{site.name}}
</option>
</select>
但是,当我在selectedSite中提供初始索引时,它不起作用,并且总是显示第一个选项。例如,如果我们将selectedSite提供为“1”,则应选择值为“1”的选项,但这不会发生
当我从下拉列表中选择选项时,其他一切都正常工作,包括$watch和selectedSite
我使用的是AngularJSV1.2.10 尝试在
$watch
处理程序的末尾调用$scope.$apply()
请参阅。尝试在
$watch
处理程序的末尾调用$scope.$apply()
请参阅。尝试使用以下方式选择的ng
<option ng-repeat="site in defaultSites" value="{{$index}}" ng-selected="{{$index == selectedSite}}">
{{site.name}}
</option>
{{site.name}
尝试使用以下方式选择的ng
<option ng-repeat="site in defaultSites" value="{{$index}}" ng-selected="{{$index == selectedSite}}">
{{site.name}}
</option>
{{site.name}