I've run into some trouble trying to write a directive to make a generic tool-tip which accepts as arguments a user id, and different actions associated with that id. Each action has it's own method in the controller and it's own icon.
This is the HTML
<tr ng-repeat="user in users"
row-actions id="user.id" actions="[{'action': editUser ,'icon': 'edit'}, {'action': removeUser, 'icon': 'trash'}]">
<td>{{user.name}}</td>
<td>{{user.unit.name}}</td>
<td>{{user.roleName}}</td>
<td>{{user.active ? 'ACTIVE' : 'NON_ACTIVE' | translate}}</td>
</tr>
This is the directive
myApp.directive('rowActions',['$compile', function($compile){
return {
restrict: 'A',
scope: {
id: '=',
actions: '='
},
link: function (scope, element, attr) {
var div = angular.element('<div class="row-actions"></div>');
for (var i=0; i < scope.actions.length; i++) {
div.append('<span class="row-action icon icon-' + action.icon + ' icon-white" ng-click="' + action.action + '(' + scope.id + ')' + '"></span>');
}
element.append(div);
$compile(element);
}
};
}]);
Basically, the methods are editUser and removeUser, I'd like to be able to call them as editUser(user.id), etc, but I can't get it to compile. I tried sending them as strings ('editUser'), and in the example they are sent as functions. Neither works.
Please take a look, Thank you
actions: '='toactions: '@'. if this doesnt work please setup a plunker