VOOZH about

URL: https://www.geeksforgeeks.org/angular-js/angularjs-ng-href-directive/

⇱ AngularJS ng-href Directive - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

AngularJS ng-href Directive

Last Updated : 11 Jul, 2025

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 then it may go to the 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> 

Parameter value:

  • addr: It refers to the string containing the angular expression.

Example 1: This example describes the use of the ng-href Directive in AngularJS, where the ng-init directive is used to initialize AngularJS Application data, & contains the URL.

Output:

👁 Image
 

Example 2: This is another example that describes the ng-href Directive in AngularJS.

Output:

👁 Image
 
Comment

Explore