[英]how to use routerLink instead of href in anchor tag in 'innerHTML' in angular2+?
In angular 2+角度 2+
In .ts在 .ts
this.htmlText = 'The validation window for <a href=\"http://localhost/nomination/">Innovator Mind</a> nominations is open now. Last date to review is 2020-Jan-25';
in HTML ,在 HTML 中,
<div [innerHTML]="htmlText "></div>
In .ts在 .ts
this.htmlText = 'The validation window for <a routerLink=\"http://localhost/nomination/">Innovator Mind</a> nominations is open now. Last date to review is 2020-Jan-25';
in HTML ,在 HTML 中,
<div [innerHTML]="htmlText"></div>
So how to achieve the route the page without reloading the page?那么如何在不重新加载页面的情况下实现页面的路由呢?
add in constructor.在构造函数中添加。
private router: Router
Use click event for change url by ts ->使用点击事件通过 ts 更改 url ->
.ts: .ts:
html='<a value="myRoute">link</a>';
changeRoute(value){
let myRoute=value.target.attributes.value.value;
if(myRoute){
this.router.navigate([ myRoute ]);
}
}
.html : .html :
<div (click)='changeRoute($event)' [innerHTML]="html"> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.