Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

AngularJS ng-href Directive

AngularJS ng-href Instruction

AngularJS Reference Manual AngularJS Reference Manual


AngularJS Examples

Use AngularJS to set and add a link:

<

div

ng-init=

"myVar = 'http://www.runoob.com'"

   

<

h1

Runoob Tutorial

<

/h1

   

<

p

Access the

<

a

ng-href=

"{{myVar}}"

{{myVar}}

<

/a

Learn!

<

/p

<

/div

Try it »


Definition and Usage

ng-href The directive overrides the native element's href attribute.

If there is AngularJS code in the value of href, you need to use ng-href instead of href。

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


Syntax

<

a

ng-href=

"string"

<

/a

elements support this directive.


Parameter value

Value Description
expression A string, the result of the expression

AngularJS Reference Manual AngularJS Reference Manual