angularjs - How to trigger binding of select based on the changed value in another select? -
let's have list of countries , each country has list of states/regions. there 2 selects. first select country, , when country changes want trigger binding of states select. how link these 2 controls trigger binding of states select when country changes?
<select id="countries" data-ng-model="vm.permanentaddress.countrycode" data-ng-options="country.code country in vm.form.countries"> </select> <select data-ng-model="vm.permanentaddress.statecode" data-ng-options="state.value state in vm.getstatesforcountry(vm.permamentaddress.countrycode)"> </select>
update: not explicit in question want do. not want create new properties watched angular change. want tell anuglar, hey has changed, go ahead , re-evaluate binding control.
is not possible?
in controller have this:
$scope.setstateoptions = function(country){ $scope.stateoptions = /* whatever code use states */ }
then html can be:
<select id="countries" data-ng-model="vm.permanentaddress.countrycode" data-ng-options="country.code country in vm.form.countries" data-ng-change="setstateoptions(country)"> </select> <select data-ng-model="vm.permanentaddress.statecode" data-ng-options="state.value state in stateoptions"> </select>
Comments
Post a Comment