加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 如何在包含ng-repeat的选择上触发ng-change

发布时间:2020-12-17 17:40:09 所属栏目:安全 来源:网络整理
导读:我有两个选择框,第二个选择框在第一个选择框更改时自动更新. labelRegion/labelselect ng-model="region" ng-change="clear(1)" ng-options="l.region for l in locations"/selectbr /labelCountry/labelselect ng-model='country' ng-change="clear(2)" ng-
我有两个选择框,第二个选择框在第一个选择框更改时自动更新.

<label>Region</label>
<select ng-model="region" 
        ng-change="clear(1)" 
        ng-options="l.region for l in locations"
></select>
<br />
<label>Country</label>
<select ng-model='country'
        ng-change="clear(2)" 
        ng-options="c.country for c in region.countries"
></select>

我的位置是一个json对象,如下所示:

[
  {region: "Europe",countries: [{country: "France"},{country: "UK"}/*,...*/]},{region: "Africa",countries: [{country: "Cameroon"},{country: "Algeria"}]}
  /*,...*/
]

这一切都很好用.

当我想将第一个选择框的值设置为Europe时,它开始变得复杂,我想在第二个选择框上触发ng-change事件.

有关如何做到这一点的任何想法?

解决方法

您希望在第二个选择框上触发ng-change事件,这相当于模型区域更改时的方案.所以你可以使用观察者来实现它.

$scope.$watch('region',function (newValue,oldValue) {
    console.log(newValue,oldValue);
})

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读