Reputation: 1031
I have issue with Event Emitter in child component.
I want to pass variable with EventEmitter to parent component, but with usage timeout function. Now it's look like this:
CHILD:
export class AlertSuccess implements OnChanges {
@Input() success: SuccessCRM;
@Output() emitCollapse:EventEmitter<any> = new EventEmitter();
private info_ico: string = require('../../public/images/iconInfoTip.png');
public state: boolean = false;
constructor() {}
collapseAlert () {
let alert = document.getElementById('success');
setTimeout(function() {
console.log("BEFORE EMITTED STATE!!!!!: ", this.state );
console.log(this.emitCollapse);
this.emitCollapse.emit(this.state);
}, 500);
}
ngOnChanges(changes: SimpleChanges):void {
console.log("CHANGES: ", this.success);
this.collapseAlert();
}
}
In parent everything is normal, I have method which I passed via template.
Emitter is working without timeout function. Please help me implement it into timeout!
Regards Bosper!
Upvotes: 2
Views: 3618
Reputation: 136154
Use Arrow function
to point correct this
.
setTimeout(() => {
console.log("BEFORE EMITTED STATE!!!!!: ", this.state );
console.log(this.emitCollapse);
this.emitCollapse.emit(this.state);
}, 500);
Upvotes: 2