AngularJS ng-href directive

Definition and Usage

ng-href Directive will override the original href attribute of the <a> element.

If the href value contains AngularJS code, then you should use ng-href Directive Replacement href.

ng-href Directives can ensure that the link does not break even if the user clicks the link before AngularJS evaluates the code.

Example

Create href using AngularJS:

<div ng-init="myVar = 'https://www.codew3c.com'">
    <h1>Tutorial</h1>
    <p>Access <a ng-href="{{myVar}}">{{myVar}}</a> to learn!</p>
</div>

Try It Yourself

Syntax

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

Affected <a> Element Support.

Parameter

Parameter Description
string A string value, or an expression that evaluates to a string.