AngularJS ng-href Instruction
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