根据当前标签内容动态修改title内容,并且屏蔽标签内的html标签
import { Directive, ElementRef, AfterContentChecked } from "@angular/core";
/**
* 给dom元素添加当前dom内容title
* 展示innerText字段,html标签不会显示在title中
*
*/
@Directive({
selector: "[appTitle]"
})
export class AppTitleDirective implements AfterContentChecked {
constructor(private elementref: ElementRef) {}
ngAfterContentChecked() {
const ele = this.elementref["nativeElement"];
ele.title = ele.innerText;
}
}