Angular 如何检查子元素是否具有类?

Angular 如何检查子元素是否具有类?,angular,Angular,我在Angular中使用ElementRef来获取DOM元素: private el: ElementRef; this.el.nativeElement.children[0]; 如何检查元素此.el.nativeElement.children[0]是否具有特定的类?如果它是一个特定的类,并且您知道它,则可以使用instanceof。比如: 它将根据结果打印正确或错误。检查蒂尔诺·巴里的答案:可能重复 console.log(this.el.nativeElement.children[

我在Angular中使用ElementRef来获取DOM元素:

private el: ElementRef;

this.el.nativeElement.children[0];

如何检查元素
此.el.nativeElement.children[0]
是否具有特定的类?

如果它是一个特定的类,并且您知道它,则可以使用instanceof。比如:


它将根据结果打印正确或错误。

检查蒂尔诺·巴里的答案:可能重复
console.log(this.el.nativeElement.children[0] instanceof ClassName);