Event to fire when an angular *ngIf statement evaluates in template
问题 If I have the following: <div *ngIf="user$ | async as user" class="container"> <p>user.name</p> </div> Is there a way I can execute code when the div above finally appears on screen? 回答1: The ngIf will remove that DOM element and all attached components/directives. So you can just write a simple directive that executes an event when it's first created. When the ngIf transitions from false to true the directive will be created (again, and again, etc...) @Directive({selector: '[after-if]'})