I have a cmd where I get the content of the page from the server. Then content can include HTML and links. The problem is when I display this data the links don't work. When looking at page source it turns out that "routerLink" is transformed into "router link" and that's why it probably doesn't work. Here is my code:
My class, notice that routerLink is in camelcase here:
export class TwoComponent implements OnInit {
data = '<a routerLink="/one">ONE</a>'; //this will actually come from backend server
constructor() { }
ngOnInit() {}
}
And my html:
<div [innerHTML]="data | bypassSecurity"></div>
And when i load this page and look at the source the routerLink is now in lowercase:
<a routerlink="/one">ONE</a>
At first, i thought it's the bypassSecurity pipe that responsible but I checked the output of the pipe and routerLink was still in camel case there. So it seems like it happens somewhere else. Just in case here is my bypassSecurity pipe too:
export class BypassSecurityPipe implements PipeTransform {
constructor(private sanitized: DomSanitizer) {}
transform(value): any {
return this.sanitized.bypassSecurityTrustHtml(value);
}
}
Any advice on where and why this lowercase transformation happens would be appreciated :)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…