我正试图为编辑/私人信息创建一个指令。
如果未提供某些信息,则应显示一个黑匣子(就像内容在那里,但用黑匣子使其不可见一样)
import { Directive, ElementRef, Renderer, OnInit } from
'@angular/core';
@Directive({
selector: '[appRedactedContent]'
})
export class RedactedContentDirective implements OnInit {
min = 75;
max = 150;
width = this.randomIntFromInterval(this.min, this.max);
constructor(private el: ElementRef,
private renderer: Renderer) {
}
ngOnInit() {
this.renderer.setElementStyle(
this.el.nativeElement, 'background-color', 'blue !important');
this.renderer.setElementStyle(this.el.nativeElement, 'width',
this.width.toString());
}
randomIntFromInterval(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1) + min);
}
}
html
<a appRedactedContent></a>
打开开发人员工具时,我可以看到添加的样式,但a标签在浏览器中看不到蓝色框