如何在角度6中为自定义组件应用CSS样式

问题描述 投票:0回答:2

我试图将css之类的显示块设置为自定义组件,但不起作用。我不知道如何设置它。

我在下面提供了我的代码。如何为此设置CSS样式?任何人都有想法吗?请帮助找到解决方案。

app.component.html

<my-custom-cmp  #myflag><my-custom-cmp>

app.component.ts

 @ViewChildren('myflag', {read: ElementRef}) el: QueryList<ElementRef>;

 ngOnInit(){

  this.el.nativeElement.style.display= 'block';

}
typescript angular6 angular5 angular7
2个回答
0
投票

尝试@ViewChild('myflag') public el: ElementRef;代替@ViewChildren('myflag', {read: ElementRef}) el: QueryList<ElementRef>;


-1
投票
@ViewChild('myflag', {read: ElementRef}) el: ElementRef;
© www.soinside.com 2019 - 2024. All rights reserved.