根据我的项目要求,我必须使用Renderer2
禁用下拉菜单。我必须禁用名称为'level'
的下拉菜单。如何获取元素名称并禁用它?我确实尝试了下面的代码,但3个功能都不起作用
constructor(private renderer: Renderer2, private el: ElementRef) {}
//Unable to hide, no console error
A() {
this.renderer.setAttribute(this.el.nativeElement, 'aria-hidden', 'true');
}
//Got console error as, nativeElement does not exist
B() {
this.renderer.setAttribute(document.getElementsByName("level").nativeElement, 'aria-hidden', 'true');
}
//Got console error as, setAttribute is not a function
C() {
this.renderer.setAttribute(document.getElementsByName("level"), 'aria-hidden', 'true');
}
请指导我哪里出了问题。