媒体查询打印的角度4指令
问题描述:
试图制作一个指令,使用打印媒体查询来隐藏元素。在纯CSS,它看起来像这样:媒体查询打印的角度4指令
@media print {
.no-print {
display: none;
}
我如何使用elementRef的指令适用于这一点,这是我到目前为止有:
constructor(el: ElementRef) {
el.nativeElement.setAttribute('style',
`@media print {
display: none;
}`
);
}
答
这可能是这样的:
@Directive({
selector: '[myDirective]',
})
export class MyDirective {
@HostBinding('class')
elementClass = 'custom-theme';
constructor() {
}
}