showing results for - "angular viewchild set attribute"
Nick
24 Jul 2018
1// If you call console.log on one of the button elements, you can see that it is an instance of ElementRef, not HTMLElement.
2
3// So...
4
5// Import ElementRef from @angular/core:
6
7import {Component, ViewChild, ElementRef} from '@angular/core';
8// Change the buttons type from HTMLElement to ElementRef:
9
10@ViewChild('roundButtonOne') roundButtonOne: ElementRef;
11@ViewChild('roundButtonTwo') roundButtonTwo: ElementRef;
12@ViewChild('roundButtonThree') roundButtonThree: ElementRef;
13// Get nativeElement from ElementRef object and then call setAttribute() / getAttribute() methods:
14
15this.roundButtonOne.nativeElement.getAttribute('xlink:href');
16
17this.roundButtonOne.nativeElement.setAttribute('xlink:href','#mic-small');
18