I've got an alert component which has a message
property. The message may be some text with a hyperlink in it:
An error occured. <a href="/learn-more">Learn more</>
The message
is inserted via innerHtml
:
<div class="alert-text" [innerHtml]="alert.message"></div>
When I click the link, it reloads the app. What can I do to fix this?
Angular: 7.1.0
innerHTML does not bind any angular event that's why it's not working to make it work you need to create custom directive which is responsible for route navigation.
check the working sample - https://stackblitz.com/edit/skdroid-innerhtml-routing
custom directive - CustomRouteDirective
html code -
<div appCustomRoute [innerHTML]="sampleHTML"></div>
Try using
routerLink
instead ofhref
.