import { Component, ElementRef, HostListener, Input } from ‘@angular/core’;
@Component({ selector: 'selector', template: ` <div> {{text}} </div> `})export class AnotherComponent { public text: String; @HostListener('document:click', ['$event']) clickout(event) { if(this.eRef.nativeElement.contains(event.target)) { this.text = "clicked inside"; } else { this.text = "clicked outside"; } } constructor(private eRef: ElementRef) { this.text = 'no clicks yet'; }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)