I'm working on an angular application that uses ng-grid through out on one of the grids I have a cell template with an ng-init function attached to one of it's dom elements.
var cellTemplate = '<div class="fooProperty" ng-init="setIcon($event, \'foo\',row.entity.foo)" ng-class="{\'foo_enabled\' : row.entity.foo, \'foo_disabled\' : !row.entity.hasFoo}" ng-click="changeRole($event, \'foo\')" title="Foo Bar"></div>'
The code I have written for setIcon in my directive is
scope.setIcon = function($event,type,iconInfo){
var target = $event.target;
var row = (target).parent().parent();
console.log(type+": "+iconInfo);
console.log(row);
};
The problem I'm having is that when the ng-init function fires I get an error message saying TypeError: Cannot read property 'target'
of undefined at var target = $event.target;
.
EDIT:
So the issue is that I can't use $event
on ng-init
since no DOM event happens. My question now is how can I edit the above code to grab the DOM element as soon as it's loaded (essentially I need to know the proper angular equivalent of onload)?