AngularJS ng-hrefDirective
AngularJS Examples
Use AngularJS to add a link:
<div ng-init="myVar = 'http://www.example.com'">
<h1>Rookie Tutorial</h1>
<p>Visit<a ng-href="{{myVar}}">{{myVar}}</a>Learn!</p>
</div>
<h1>Rookie Tutorial</h1>
<p>Visit<a ng-href="{{myVar}}">{{myVar}}</a>Learn!</p>
</div>
Try it Yourself »
Definition and Usage
ng-hrefThe directive overrides the native <a> element href attribute.
If there is AngularJS code in the href value, you need to useng-hrefinstead ofhref。
ng-hrefThe directive ensures the link works properly, even if the link is clicked before AngularJS executes the code.
Syntax
<a ng-href="string"></a>
The <a> element supports this directive.
Parameter Values
| Value | Description |
|---|---|
| expression | String, the result of the expression |
Other Extensions
AngularJS Reference Manual