Skip to main content

How to use ng-href directive in AngularJS

ng-Href Directive 

                ng-Href directive is hyper link markup to a text in angularJs. This hyperlink will change able to implement dynamic url {{hash}} value. Hash value to assign in a controller to happened user click event fire to assign dynamic url. This Value is undefined means it will return to 404 page.

ng-Href directive Example 

HTML:
  
  <div ng-app="anchor">
    <div ng-controller="anchorController">
        <a ng-href="http://www.google.com" ng-click="show($event)">Anchor Tag</a>
    </div>
  </div>

Javascript : 

var anch = angular.module('anchor', []);
anch.controller('anchorController',['$scope', '$window', function($scope, $window){
    $scope.show = function(obj) {
      $window.open(obj.target.href);
    }
}]);

Result : 

Comments

Post a Comment