मेरे बच्चे घटक में ngOnChanges` काम:`निम्नलिखित के रूप में बनाने के लिए` 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);
}
}
और माता पिता के घटक के रूप में निम्नलिखित:
'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'
};
}
}
हर बार जब मैं "अपडेट" बटन क्लिक किया , ngOnChanges
विधि कभी नहीं बुलाया जाए, लेकिन क्यों?
मैं कोणीय संस्करण मैं उपयोग कर रहा हूँ कि "2.0.0-beta.8"
क्या आप निश्चित हैं? क्योंकि मुझे लगता है कि जब आप 'अपडेट' बटन पर क्लिक करते हैं तो इसे निकाल दिया जाता है। – micronyks