现在位置: 首页 > AngularJS 教程 > 正文

AngularJS ng-href 指令

AngularJS 参考手册 AngularJS 参考手册


AngularJS 实例

使用 AngularJS 设置添加链接:

<div ng-init="myVar = 'http://www.runoob.com'">
    <h1>菜鸟教程</h1>
    <p>访问 <a ng-href="{{myVar}}">{{myVar}}</a> 学习!</p>
</div>

尝试一下 »

定义和用法

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

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

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


语法

<a ng-href="string"></a>

<a> 元素支持该指令。


参数值

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

AngularJS 参考手册 AngularJS 参考手册