I have an Angular 2 component which, on some user action, loads html from a database. The html contains anchor tags with relative paths. Given that I don't want the whole application to reload when the user clicks the link, I am trying to use the routerLink directive; however, since this html is loaded dynamically, the routerLink is not processed. The html will not contain any other angular directives. What is the simplest way to achieve this? See my example below.
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `<h1>Hello {{name}}</h1>
<p><a (click)="GetTextFromDatabase()">Get data from database</a> which should contain a <a routerLink="/some-route">working link</a></p>
<div [innerHTML]="data"></div>
<router-outlet></router-outlet>`,
})
export class AppComponent {
name: string = 'Angular';
data: string;
private GetTextFromDatabase(): void {
this.data = '<p>here is my paragraph containing a <a routerLink="/some-route">link</a>';
}
}