I use tree grid plugin (from this link: https://github.com/khan4019/tree-grid-directive)
and i custom i little bit it's template:
.directive('treeGrid', [
'$timeout', function($timeout) {
return {
restrict: 'E',
template:
"<div class=\"table-responsive\">\
<table id=\"policies\" class=\"table table-striped\">\
<colgroup>\
<col width=\"10%\" />\
<col width=\"70%\" />\
<col width=\"1%\" />\
<col width=\"1%\" />\
</colgroup>\
<thead>\
<tr>\
<th>Category</th>\
<th>Content</th>\
<th></th>\
<th></th>\
<th></th>\
</tr>\
</thead>\
<tbody>\
<tr ng-repeat=\"row in tree_rows | filter:{visible:true} track by row.branch.uid\" ng-class=\"'level-' + {{ row.level }} + (row.branch.selected ? ' active':'')\">\
<td class=\"text-primary\"><a ng-click=\"user_clicks_branch(row.branch)\"><i ng-class=\"row.tree_icon\"ng-click=\"row.branch.expanded = !row.branch.expanded\"class=\"indented tree-icon\"></i></a>\
<span class=\"indented tree-label\" ng-click=\"user_clicks_branch(row.branch)\"> {{row.branch[expandingProperty]}}</span></td>\
<td ng-bind-html=\"row.branch[colDefinitions[2].field]\"></td>\
<td> <a href=\"javascript:void(0)\" ng-click=\"editContent(row.branch)\" data-toggle=\"modal\" data-target=\"#new-content\" class=\"action\"><i class=\"glyphicon glyphicon-edit\"></i></a> </td>\
<td> <a ng-click=\"deleteContent(row.branch.Id)\" class=\"action\"><i class=\"glyphicon glyphicon-remove-circle\"></i></a> </td>\
</tr>\
</tbody>\
</table>\
</div>",
replace: true,
scope: {
treeData: '=',
colDefs:'=',
expandOn:'=',
onSelect: '&',
deleteContent: '&',
editContent: '&',
initialSelection: '@',
treeControl: '='
},
and such controller:
.controller('ContentCtrl', ['$http', '$scope', '$location', '$localStorage', 'authService', 'settings', function ($http, $scope, $location, $localStorage, authService, settings) {
$scope.deleteContent = function(){
console.log("delete");
};
}]);
and view:
<tree-grid tree-data="policies"></tree-grid>
but when i click on my delete link, i get nothing, it didn't go to controller scope functions (
but why? what i do wrong?
i could write in dirty way this functions in directive, but this is a bad idea ((
how to solve it?
deleteContent({id: row.branch.Id})in your directive template, while consuming it<tree-grid tree-data="policies" delete-content="deleteContent(id)"></tree-grid>and just get the id now in your controller method as argument, i.e$scope.deleteContent = function(id){console.log("delete for id:" + id);};