![](/img/trans.png)
[英]Angular Animations : How to bind animation trigger name dynamically in the template?
[英]How to bind <a href>template in angular 2 dynamically?
請找到下面的代碼
Component.ts
getReply():string{if(condition){
return "The link is: <a href = 'https://www.google.com'>Google</a>";
}
我在前端使用[innerHtml]綁定上述內容,使用該代碼綁定上面的代碼並在指向Google網站的點擊時顯示鏈接。
而當我嘗試動態創建鏈接時,該鏈接會顯示但未定向到Google網站。請在我嘗試的方法下方找到,
Component.ts
export class ReplyComponent{
link : string;
getReply():string{if(condition){
this.link = "https://www.google.com";
return "The link is: <a href = 'this.link'>Google</a>";
}
}
嘗試此操作后,我能夠獲得鏈接,但是它沒有重定向到Google網站。 如果我做錯了,請糾正我。
您的語法有問題。 return語句全為字符串。
return "The link is: <a href = 'this.link'>Google</a>";
在這里,return語句將其作為字符串返回。 為了達到動態效果,請按如下所示更改您的返回值:
return "The link is: <a href = "+this.link+">Google</a>";
因此this.link
被視為變量而不是字符串。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.