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>
</div>

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

Comments

Click here to write/view comments