My składnikiem dziecięcej w następujący sposób:Jak `ngOnChanges` pracę w` angular2`
'use strict';
import {Component, Input, OnInit, OnChanges, ChangeDetectionStrategy, ElementRef} from 'angular2/core';
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: 'my-app',
template: ''
})
export class MyApp implements OnInit {
@Input() options: any;
constructor(private el: ElementRef) {
}
ngOnInit() {
}
ngOnChanges(...args: any[]) {
console.log('changing', args);
}
}
i komponent Parent w następujący sposób:
'use strict';
import {Component, Input} from 'angular2/core';
import {MyApp} from './MyApp';
@Component({
selector: 'map-presentation',
template: `<my-app [options]="opts"></my-app>
<button (click)="updates($event)">UPDATES</button>
`,
directives: [MyApp]
})
export class MainApp {
opts: any;
constructor() {
this.opts = {
width: 500,
height: 600
};
}
updates() {
console.log('before changes');
this.opts = {
name: 'nanfeng'
};
}
}
Za każdym razem, gdy kliknąłem przycisk "Aktualizacje" , metoda ngOnChanges
nigdy nie zostanie wywołana, ale dlaczego?
wersja kątowa ja używam to "2.0.0-beta.8"
Czy jesteś pewien? ponieważ myślę, że zostanie uruchomiony, gdy klikniesz przycisk "update". – micronyks