As seen in this plunker, I'm dynamically adding an HTML to one of my elements, which boils down to this:
@Component({
selector: 'my-comp',
template: `<span [innerHTML]="link"></span>`,
}) export class MyComponent {
private linkContent = '<a routerLink="/my-route">GoTo Route</a>';
private link;
constructor(sanitizer: DomSanitizer) {
this.link = sanitizer.bypassSecurityTrustHtml(linkContent);
}
}
This results in <a routerLink="/my-route">GoTo Route</a>
being added to the DOM, but Angular knows nothing about the routerLink
directive on this element, and does not "bind" to it. So, when you click the link, it results in complete reload with re-bootstrap (which doesn't work in plunk, it just gives a 404).
Question: how to tell angular to go through the DOM (or its part, or even a single element) and perform component initialization if needed?