Question

I am trying to create a popover to confirm a delete operation. I create the popover using the clickover bootstrap plugin (3rd party) and created a directive.

The problem is that I am not being able to access the parent/sibling scope from the compiled html for the popover buttons.

In pratical terms, what this code is not doing is to call the destroy function in the scope with the iteration variable (v) from the delete button in the popover.

JSFiddle:

http://jsfiddle.net/maralc/PCB2D/

Bellow is the code for the directive:

function TestCtrl($scope) {
    $scope.list = {
         id: [{
             value: 1},
         {
             value: 2},
         {
             value: 3}]
     };
     $scope.destroy = function(id) {
         console.log("destroy called (" + id + ")");
     }
 }

 angular.module('TestApp', []).directive('buttonDelete', function($compile, $rootScope)      {
     return {
         restrict: 'E',
         replace: true,
         template: '<a class="button-delete"><i style="margin-top: 4px;" class="icon-     remove"></i></a>',
    link: function(scope, element, attrs) {
        //            debugger;
        //element.bind('click', function(e) {
        //                var popover = $();
        //                element.clickover({content: 'test'});
        element.clickover({
            global: true,
            title: 'Are you sure?',
            content: function() {
                //debugger;
                var element = $compile("<div class='btn-toolbar'><button id='button-confirm-delete-cancel' data-dismiss='clickover' class='btn'>Cancel</button><button id='button-confirm-delete-ok' class='btn btn-danger' ng-click='destroy(v)'>Delete</button></div>")(scope.$parent);
                return element.html();
            }
            //});
        });
    }
}
});​
Was it helpful?

Solution

It looks like it's working for me... v is an object not an index, such as:

{value: 2}

So from your destroy function just do id.value to get the id. Or I'd suggest updating your repeat expression to:

v.id in list.id

Or rename from ID, it's confusing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top