I have two components. One for parent and another one for child. I want to set matTooltip
attribute in parent component element from child component. I have tried this below:
@ViewChild('contentWrapper') content: ElementRef;// getting parent component element
ngAfterViewInit() {
this.renderer.setAttribute(this.content.nativeElement.parentElement.parentElement, 'matTooltip',
this.content.nativeElement.innerText);
}
It's rendered in browser like:
<span id="popuptrigger" style="position: absolute;margin-top: -8px"
mattooltip=" Soft drinks, coffees, teas, beers, and ales "> Soft drinks,
coffees, teas, beers,</span>
I can see the mattooltip
attribute in the span element.but I am unable to see the ToolTip .
On the other hand, this is working fine for title
attribute:
this.renderer.setAttribute(this.content.nativeElement.parentElement.parentElement, 'title',
this.content.nativeElement.innerText);
}