मेरे पास इनपुट के साथ एक सरल कस्टम निर्देश है, कि मैं अपने घटक में बाध्यकारी हूं। लेकिन किसी भी कारण से, इनपुट संपत्ति की बाल संपत्ति को बदलते समय ngOnchanges() विधि आग नहीं होती है।कोणीय 2 बाल संपत्ति बाध्य संपत्ति पर फायरिंग अपडेट नहीं बदलती
my.component.ts
import {Component} from 'angular2/core';
import {MyDirective} from './my.directive';
@Component({
directives: [MyDirective],
selector: 'my-component',
templateUrl: 'Template.html'
})
export class MyComponent {
test: { one: string; } = { one: "1" }
constructor() {
this.test.one = "2";
}
clicked() {
console.log("clicked");
var test2: { one: string; } = { one :"3" };
this.test = test2; // THIS WORKS - because I'm changing the entire object
this.test.one = "4"; //THIS DOES NOT WORK - ngOnChanges is NOT fired=
}
}
my.directive.ts
import {Directive, Input} from 'angular2/core';
import {OnChanges} from 'angular2/core';
@Directive({
selector: '[my-directive]',
inputs: ['test']
})
export class MyDirective implements OnChanges {
test: { one: string; } = { one: "" }
constructor() { }
ngOnChanges(value) {
console.log(value);
}
}
template.html
<div (click)="clicked()"> Click to change </div>
<div my-directive [(test)]="test">
किसी को भी मुझे बता सकते हैं क्यों?
न तो इनमें से मेरे लिए काम करने लगते हैं। मैंने testChange emitter को @Ouput() पर स्पष्ट रूप से सेट करने का प्रयास किया और मान के साथ टाइप-एड्रेक होने का प्रयास किया, लेकिन यह निर्देश में ngOnchanges को आग नहीं लगाता है। –
Dynde
एंगुलर 2 का कौन सा संस्करण आप उपयोग करते हैं क्योंकि मैंने इसे बीटा 0 के साथ काम किया है? –
मैं beta.0 पर भी हूं। आपका testChange घोषणा मेरे लिए भी अमान्य है (या तो असाइन करना है या टाइप घोषणा को पूर्ववत करना है और सीधे यहां जाना है: testChange = new EventEmitter();) क्या मुझे पंजीकरण के लिए मेरे निर्देश में कुछ विशेष तरीके से सदस्यता लेनी है घटनाइमीटर? –
Dynde