Tutorials References Exercises Bootcamp Menu
Sign Up Create Website Get Certified Pro

AngularJS ng-href Directive


Make a href using AngularJS:

<div ng-init="myVar = 'https://www.w3schools.com'">
    <p>Go to <a ng-href="{{myVar}}">{{myVar}}</a> to learn!</p>
Try it Yourself »

Definition and Usage

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

The ng-href directive should be used instead of href if you have AngularJS code inside the href value.

The ng-href directive makes sure the link is not broken even if the user clicks the link before AngularJS has evaluated the code.


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

Supported by the <a> element.

Parameter Values

Value Description
string A string value, or an expression resulting in a string.