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); }) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |