Is there a way to get the encapsulation host id that is given to a component?
If you have a component that is using ViewEncapsulation.Emulated
the element in the DOM will have an attribute name of something like _nghost-par-2.
Which, is a unique ID given to the component to encapsulate the associated styles.
How do you get that ID as part of the component's constructor?
Something to the effect of:
@Component({
hostId:string;
...
})
export class myComponent implements OnInit {
constructor(host:Host) {
this.hostId = host.id;
}
...
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…