Skip to content
Related Articles

Related Articles

AngularJS | ng-href Directive
  • Last Updated : 28 Mar, 2019

The ng-href directive is used when we have an angular expression inside the href value. If href attribute is used then the problem is that if in case the link is clicked before AngularJS has replaced the expression with its value than it may go to wrong URL and the link will be broken and will most likely return a 404 error while ng-href directive checks that the link is not broken even if the link is clicked before the code evaluation by AngularJS.

Syntax:

 <element ng-href="addr"> content ... </element> 

Where addr refers to the string containing angular expression.

Example:




<!DOCTYPE html>
<html>
   1.6.9/angular.min.js"></script>
  <body ng-app="" style="text-align:center">
    <div ng-init="url = 'https://www.geeksforgeeks.org/'">
    <h1 style="color:green">GeeksforGeeks</h1>
                <h2>ng-href Directive</h2>
    <p>Go to <a ng-href="{{url}}">GeeksforGeeks</a></p>
    </div>
  </body>
</html


Output:
ng-href

My Personal Notes arrow_drop_up
Recommended Articles
Page :