admin管理员组文章数量:1334704
I have an Angular 6 application where a ponent is used to display a message on the page. Some of the messages contain hyperlinks embedded in them (in HTML markup). However, when the messages are displayed on the page, they are getting displayed in plain text (hyperlinks are not rendered, but the markup is displayed to the user instead).
You can visit Stackblitz @ for a sample application that I created to explain the issue.
Expected message display:
Click here.
Actual message display:
Click <a href=''>here</a>
I have an Angular 6 application where a ponent is used to display a message on the page. Some of the messages contain hyperlinks embedded in them (in HTML markup). However, when the messages are displayed on the page, they are getting displayed in plain text (hyperlinks are not rendered, but the markup is displayed to the user instead).
You can visit Stackblitz @ https://stackblitz./edit/angular-jj5nms for a sample application that I created to explain the issue.
Expected message display:
Click here.
Actual message display:
Share Improve this question edited Jul 30, 2018 at 5:24 Vini asked Jul 30, 2018 at 5:15 ViniVini 8,41911 gold badges38 silver badges50 bronze badgesClick <a href='http://www.google.'>here</a>
3 Answers
Reset to default 5If you want to render HTML, you need to bind to the innerHTML
property of an element, for example:
<p [innerHTML]="message | async"></p>
Where message
is your observable from the service.
Using handlebars to render message
is just rendering plain text, binding to innerHTML
and using the async
will render your html content.
You can use innerHTML
In your ponent:
linkHtml = "Click <a href='http://www.google.'>here</a>"
In your template:
<div [innerHTML]="linkHtml"></div>
You can use like that: in your .ts file :
dummyLinkText: string = "Click <a href='https://www.google.'>here</a>";
and in your .html file:
<div [innerHTML]="dummyLinkText | translate"></div>
本文标签: javascriptHow to render a hyperlink in a component template in Angular 6Stack Overflow
版权声明:本文标题:javascript - How to render a hyperlink in a component template in Angular 6? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742367696a2461620.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论