Angular custom clickaway listener is triggered if a child component is removed using *ngIf
问题 I have a clickaway listener as a directive that uses @HostListener put on App.component.ts @Component({ selector: "app-root", templateUrl: "./app.component.html", styleUrls: ["./app.component.css"], }) export class AppComponent { constructor(private clickaway: ClickawayService) {} @HostListener("document:click", ["$event"]) documentClick(event: any): void { this.clickaway.target.next(event.target); } } @Directive({ selector: "[clickaway]", }) export class ClickawayDirective implements OnInit,