SoFunction
Updated on 2025-04-04

AngularJS basic ng-href directive usage

AngularJS ng-href directive

AngularJS instance

Add links using AngularJS settings:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="/libs//1.4.6/"></script>
</head>
<body ng-app="">

<div ng-init="myVar = ''">
<h1></h1>
<p>access <a ng-href="{{myVar}}">{{myVar}}</a> study!</p>
</div>

<p>This instance can use native href property,But in AngularJS middle, ng-href property更安全。</p>

</body>
</html>

Definition and usage

ng-hrefDirectives override the native <a> element href attribute.

If you have AngularJS code in the value of href, you need to use ng-href instead of href.

The ng-href directive ensures that the link is normal, even if you click the link before AngularJS executes the code.

grammar

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

The <a> element supports this directive.

Parameter value

value describe
expression string, expression execution result

The above is a compilation of AngularJS no-href data. We will continue to add it later. I hope it can help students who study AngularJS.