AngularJS ng-href 指令

AngularJS ng-href 指令

AngularJS 参考手册 AngularJS 参考手册

AngularJS 实例

使用 AngularJS 设置添加链接:


  
  
<div ng-init="myVar = 'http://www.zhishitu.com'">
    <h1>知识兔</h1>
    <p>访问 <a ng-href="https://zhishitu.com/" target="_blank">"{{myVar}}">{{myVar}}</a> 学习!</p>
</div>

知识兔 »

定义和用法

ng-href 指令覆盖了原生的 <a> 元素 href 属性。

如果在 href 的值中有 AngularJS 代码,则需要使用 ng-href 而不是 href

ng-href 指令确保了链接是正常的,即使在 AngularJS 执行代码前点击链接。

语法

<a ng-href="https://zhishitu.com/" target="_blank">"string"></a>

<a> 元素支持该指令。

参数值

描述
expression 字符串,表达式的执行结果

AngularJS 参考手册 AngularJS 参考手册

计算机