Search code examples
angularangular7

Angular access dom elements


I have an angular 7 project where several menu items are rendered using anchor tag by lib component from node_modules.

In my component, I would like to remove an attribute ('rel') from the tag. The tag does not have ID's associated to them and just have class attribute. Using this how can i remove an attribute from the tag ?


Solution

  • You can use Renderer2 to select the element and set rel property to null

    constructor(private renderer: Renderer2, private el: ElementRef) {}
    
    renderer.setElementAttribute(this.el.nativeElement.querySelector('.myClass'), 'rel',null);