ng href directives in angularjs

ng-href directives in angularjs

The ng-href is a angular directive just like href tag both are working same. The ng-href directive is standard way to use angularjs and bind it dynamically URLs to user data. 

If not, your href are broken when they contain interpolation directives.

for example. The hreftag will look like in angular

    <a href="{{ username }}" target="_self"  title="{{username}} >Facebook Page</a>

for example. in angular ng-href  directive will look like.

    <a ng-href="{{username}}" target="_self" title="{{username}}">My Facebook Page..</a>

The detail example of ng-href  directive as given below.

<!DOCTYPE html>
<head lang="en">
    <meta charset="utf-8">

    <script type="text/javascript" src=""></script>
    <script type="text/javascript">
        var ng = angular.module("app", []);

        ng.controller("controller", function ($scope) {
            $scope.username = "anilsinghkushinagar";

<body ng-app="app">
    <div ng-controller="controller">
        <div>Click on below links.</div>
            <a ng-href="{{username}}" title="{{username}}" target="_self">My Facebook Page..</a>
            <a href="{{ username }}">Facebook Page</a>


The output look like below.


Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog -
My Books - Book 1 and Book 2 Powered by Blogger.