Renderer2:无法使用“名称”属性禁用下拉列表

时间:2018-07-19 12:45:44

标签: angular renderer elementref

根据我的项目要求,我必须使用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');
    }

请指导我哪里出了问题。

0 个答案:

没有答案