How to call ng-change on select that contains ng-repeat

I have two selection windows, the second selection flag is updated when the first selection flag is changed.

<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>

My locations is a json object that looks like this:

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

It all works great.

This starts to get complicated when I want to set the value of the first selection window to Europe, and I want to fire the ng-change event in the second selection field.

Any idea on how to do this?

+5
source share
2 answers

You want to trigger an event ng-changein the second selection field, which is equivalent to the script when the model changes region. That way you can use an observer to achieve it.

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

onchange, ? , , ng-, select.

+1

All Articles