我正在Angular应用程序上工作,在这里我通过移动设备的浏览器在watsapp应用程序上共享内容。 在移动WhatsApp应用程序上轻松共享内容
但是当我尝试通过插值将数据绑定到数据时,数据 未共享
我在下面共享代码->
ts
team1 : any = 'India';
team2 : any = 'japan';
html
<a
href="whatsapp://send?text="
title="Share On Whatsapp"
onclick="window.open('whatsapp://send?text=%20{{team1}}%20vs%20{{team2}}%20Take%20a%20look%20at%20this%20awesome%20page%20-%20'
+ encodeURIComponent(document.URL)); return false;">
whatsapp share
</a>
问题->由于安全性,onclick方法不支持插值 原因,那么我该如何解决这个问题
答案 0 :(得分:1)
请尝试以下操作:
<a
href="whatsapp://send?text="
title="Share On Whatsapp"
onclick="window.open('whatsapp://send?text=%20' + team1 +'%20vs%20' + team2 + '%20Take%20a%20look%20at%20this%20awesome%20page%20-%20'
+ encodeURIComponent(document.URL)); return false;">
whatsapp share
</a>
您不需要双花括号,因为您正在传递变量。 或者,您也可以在打字稿中准备字符串。
private whatsupUrl : string;
this.whatsupUrl = `whatsapp://send?text=%20${this.team1}%20vs%20${this.team2}%20Take%20a%20look%20at%20this%20awesome%20page%20-%20`;
<a
href="whatsapp://send?text="
title="Share On Whatsapp"
onclick="window.open(whatsupUrl + encodeURIComponent(document.URL)); return false;">
whatsapp share
</a>