nick_1002 nick_1002 - 1 year ago 110
AngularJS Question

Angular/Google Analytics ng-repeat list

Quick question, I can't find anywhere how to send the selected list element in an ng-repeat to GA. Maybe with Angularitics etc?

My thinking so far was something like:

<li ng-repeat="x in x" onClick="ga('send', 'event', 'link', 'selected', $parent.x;">

The problem is how do I send the "$parent.x" through as the GA category

Can't seem to get it to work though. Thanks!

Answer Source

The idea of Angular is that it is a MVC. This being the case, the HTML doesn't have an idea what $parent is and you need to have a common 'scope' between the HTML and the Javascript. This is why there is the built in $scope so if in my controller I had $scope.newX = $parent.x then in my HTML I can pass ng-click="myFunction(newX)" and it will pass it the value of the $scope.newX

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download