Issue
Is there a way in Angular2 to have an event fired when my component becomes visible? It is placed in a tabcontrol and I want to be notified when the user switches. I'd like my component to fire an event.
Solution
What I finally did (which is not very beautiful but works while I don't have a better way to do it...) is to use the ngAfterContentChecked()
callback and handle the change myself.
@ViewChild('map') m;
private isVisible: boolean = false;
ngAfterContentChecked(): void
{
if (this.isVisible == false && this.m.nativeElement.offsetParent != null)
{
console.log('isVisible switched from false to true');
this.isVisible = true;
this.Refresh();
}
else if (this.isVisible == true && this.m.nativeElement.offsetParent == null)
{
console.log('isVisible switched from true to false');
this.isVisible = false;
}
}
Answered By - Shimrod
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.