English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

AngularJS ng-href directive

AngularJS Reference Manual

<!DOCTYPE html>
<html>
<head>
<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 = 'http://www.oldtoolbag.com'">
<h1>Basic Tutorial Website</h1>
<p>Access the <a ng-href="{{myVar}}">{{myVar}}</a> Learn!!/p>
</div>
<p>This example can use the native href attribute, but in AngularJS, the ng-href attribute is safer.</p>
</body>
</html>
Test to see ‹/›

Definition and Usage

ng-href The directive overrides the original href attribute of the <a> element.

If there is AngularJS code in the value of href, then you need to use ng-href  Instead of href.

ng-href The directive ensures that the link is normal even if the link is clicked before AngularJS executes the code.

Syntax

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

The <a> element supports this directive.

Parameter Value

ValueDescription
expressionThe execution result of a string, expression

AngularJS Reference Manual