AngularJS ng-href example

AngularJS directive ng-href can be used to use a template to create href. Directly using it in href can make the link broken before Angular get a chnce to evaluate it.

<div ng-app="myApp" ng-controller='MyCtrl'>
  <button ng-click="link1='/tutorials/'">click to set variable link1</button><br/>
  <a ng-href="{{link1}}">This will become a link if variable link1 is set</a>

<script src="//"></script>
  var module = angular.module('myApp', []);
  module.controller('MyCtrl', function($scope) {});
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments