We need to track clicks in some buttons inside a body owned by a ng-controller
.
The elements are not created by directives, before the angular initialzation, the HTML is something like:
<html>
<body ng-controller="SomeController" ng-init="someFunction()">
<a id="myButtonId" name="somNameOfInteres" ng-click="doSomething()">My Link</a>
</body>
</html>
We use Google Tag Manager for attaching some jQuery and non-jQuery events in links and buttons inside the body:
jQuery('a[name="somNameOfInteres"]').on('mousedown', function () {
// send some events to Google Analytics
});
// or
document.getElementById('myButtonId').addEventListener('mousedown', function () {
// send some events to Google Analytics
});
In both cases, the ng-init
function seems to remove all event listeners in all elements inside the html body.
I have tried to put my event listener inside:
angular.element(document).ready(function() {
jQuery('a[name="somNameOfInteres"]').on('mousedown', function () {
// send some events to Google Analytics
});
});
But this didn't work either.
How can I add these event listeners without they get removed by Angular?