![](/img/trans.png)
[英]Remove class from Viewchild Element after setTimeout in Angular2
[英]Change element class on ViewChild in Angular 2
我在Angular 2中使用ViewChild来隔离一个元素。 我可以直接操作样式,但是如果可以更改元素样式类,我找不到文档。
这是示例代码:
export class HomeComponent implements OnInit {
@ViewChild('slideBg') el:ElementRef;
ngAfterViewInit {
// style can be changed
this.el.nativeElement.style.background = 'red';
// does not work:
this.el.nativeElement.class = 'myCSSclass';
}
…
}
想看看这是否可行以及如何实现。 任何帮助赞赏。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.