, , , , .
. , , , ng-change Angular.
. , , .
- on-change:
<country-chooser
country="vm.country"
country-change="vm.countryChange($event)">
</country-chooser>
<country-chooser
country="vm.country"
country-change="vm.country=$event">
</country-chooser>
:
app.directive('countryChooser', function() {
return {
template: `<select ng-model="$ctrl.country"
ng-change="$ctrl.countryChange({'$event': vm.country})"
ng-options="country for country in $ctrl.countries">
</select>
`,
scope: {
country: '<',
countryChange: '&'
},
bindToController: true,
controllerAs: '$ctrl',
:
vm.countryChange = function(country) {
console.log('*** countryChange callback ***');
console.log('country:', country);
};
, .
DEMO PLNKR.
AngularJS v1.5 Angular2 + Ready
app.component('countryChooser', {
template: `<select ng-model="$ctrl.country"
ng-change="$ctrl.countryChange({'$event': vm.country})"
ng-options="country for country in $ctrl.countries">
</select>
`,
bindings: {
countries: '<'
country: '<',
countryChange: '&'
}
});
AngularJS v1.5 , Angular2 +.
Angular2 +, (=). < &.
Angular2 + - .
<country-chooser [(country)]="vm.country">
</country-chooser>
Angular2 + de-sugars :
<country-chooser [country]="vm.country" (countryChange)="vm.country=$event">
</country-chooser>
. @ Angular - ()