Skip to content
Related Articles

Related Articles

Improve Article

AngularJS | ng-href Directive

  • Last Updated : 28 Mar, 2019
Geek Week

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.


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

Where addr refers to the string containing angular expression.


<!DOCTYPE html>
  <body ng-app="" style="text-align:center">
    <div ng-init="url = ''">
    <h1 style="color:green">GeeksforGeeks</h1>
                <h2>ng-href Directive</h2>
    <p>Go to <a ng-href="{{url}}">GeeksforGeeks</a></p>


My Personal Notes arrow_drop_up
Recommended Articles
Page :