AngularJS ng-href 指令

返回到:AngularJS 参考手册

定义和用法

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

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

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

语法

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

<a> 元素支持该指令。

参数值

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

AngularJS 实例

使用 AngularJS 设置添加链接:

<!DOCTYPE html>
<html>
<head>
 <title>AngularJS 实例 | Web176教程网web176.com</title>
<meta charset="utf-8">
<script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js"></script>
</head>
<body ng-app="">

<div ng-init="myVar = 'https://www.web176.com'">
<h1>Web176教程网</h1>
<p>访问 <a ng-href="{{myVar}}">{{myVar}}</a> 学习!</p>
</div>

<p>该实例可以使用了原生的 href 属性,但在 AngularJS 中, ng-href 属性更安全。</p>

</body>
</html>

返回到:AngularJS 参考手册

terry

这个人很懒,什么都没有留下~

Share
Published by
terry

Recent Posts

自定义指令:聊聊vue中的自定义指令应用法则

今天我们来聊聊vue中的自定义…

4 天 ago

聊聊Vue中@click.stop和@click.prevent

一起来学下聊聊Vue中@cli…

2 周 ago

Nginx 基本操作:启动、停止、重启命令。

我们来学习Nginx基础操作:…

2 周 ago

Vue3:手动清理keep-alive组件缓存的方法

Vue3中手动清理keep-a…

2 周 ago

聊聊React和Vue组件更新的实现及区别

React 和 Vue 都是当…

3 周 ago