multiple anchor tags click event using angularjs -


i have multiple anchors tags in document, want put 1 function every anchor tag click, example in jquery

$(document).on('click','a',function(){      window.location.href='/home.html' }); 

how need write in angularjs. can please me?

you can make directive , add anchor tag

app.directive('myevent', function() {     return {         restrict: 'a',         link: function(scope, element, attrs) {             element.bind('click', function($event) {                 $window..location.href = '/home.html' //your link here             });         }     } }); 

in view can anchor tag or normal div

<div myevent class="click">click me</div>

or

<a myevent href="#">click me</a>

it work around prefer use jquery more appropriate this. hope helps. thank you.


there many other ways using ng-click div tag same.

<div ng-click="myevent()"></div>

in controller can use

$scope.myevent() {  $window..location.href = '/home.html' //your link here } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -