afjm
afjm

Reputation: 179

Dynamically insert angularJS contextMenu on HTML tags

I am using this angularJS contextMenu module on my application and I need to insert this inside some HTML tags dynamically. I am trying something like this but it isn't working.

e.client.html("<a context-menu=\"menuOptions\">click here</a>");

I have menuOptionsdeclared on my scope like this:

$scope.menuOptions = [
    {
        text: 'Object-Select',
        click: function ($itemScope, $event, modelValue, text, $li) {
            $scope.selected = $itemScope.item.name;
        }
    },
    {
        text: 'Object-Remove',
        click: function ($itemScope, $event, modelValue, text, $li) {
            $scope.items.splice($itemScope.$index, 1);
        }
    }
];

Someone know how to do that?

Upvotes: 0

Views: 389

Answers (1)

scipper
scipper

Reputation: 3153

You need angular to compile your dynamic context menu, so it can handle the context-menu directive. The best way doing this is:

//define the Html to insert in a variable:
var dynContextMenu = "<a context-menu=\"menuOptions\">click here</a>";

//append to content
e.client.html(dynContextMenu);

//then compile it
$compile(dynContextMenu)($scope);

I hope this helps.

Upvotes: 1

Related Questions