我如何用ng-href超链接 elements?

问题描述 投票:0回答:2

我有一个表,对于其中一个列,我正在尝试使用单个单词来链接网址,例如“Here”。但是,该列显示为空白(以及在intelliJ上显示“不允许属性ng-href”警告。这就是表格的样子,最后一行是我尝试超链接:

<tr>
<td ng-bind="order.paid | date:'short'"></td>
<td ng-bind="order.totalQty"></td>
<td ng-bind="order.total.pretty" ng-if="!store.shopifyInstalled"></td>
<td><a ng-href="order.shopifyReceiptUrl" ng-bind="Here" ng-if="store.shopifyInstalled"></a></td>
</tr>

我究竟做错了什么?

javascript html angularjs hyperlink
2个回答
0
投票

使用花括号{{}}放置模型并删除ng-bind指令。

<tr>
<td ng-bind="order.paid | date:'short'"></td>
<td ng-bind="order.totalQty"></td>
<td ng-bind="order.total.pretty" ng-if="!store.shopifyInstalled"></td>
<td><a ng-href="{{order.shopifyReceiptUrl}}" ng-if="store.shopifyInstalled">Here</a></td>
</tr>

0
投票

可以用两种方式完成:

首先使用ng-init定义var:

<td><a ng-href="order.shopifyReceiptUrl" ng-bind="var_name" ng-init="var_name='Here'" ng-if="store.shopifyInstalled"></a></td>

二,使用自定义文字:

<td><a ng-href="order.shopifyReceiptUrl" ng-if="store.shopifyInstalled">HERE</a></td>
© www.soinside.com 2019 - 2024. All rights reserved.