![](/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.