AngularJS Basic ng href Directive Usage

  • 2021-07-07 06:09:13
  • OfStack

AngularJS ng-href Directive

AngularJS instance

Add links using AngularJS settings:


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body ng-app="">

<div ng-init="myVar = 'http://www.runoob.com'">
<h1> Rookie tutorial </h1>
<p> Visit  <a ng-href="{{myVar}}">{{myVar}}</a>  Learning !</p>
</div>

<p> This instance can use the native  href  Property, but in the  AngularJS  In,  ng-href  Property is safer. </p>

</body>
</html>

Definition and usage

The ng-href instruction overrides the native < a > Element href attribute.

If you have an 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 the link is clicked before AngularJS executes the code.

Grammar

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

< a > Element supports this directive.

Parameter value

描述
expression 字符串,表达式的执行结果

The above is the collation of AngularJS no-href data, which will be supplemented in the future, hoping to help students who learn AngularJS.


Related articles: