在 HTML 标签上动态插入 angularJS contextMenu
Dynamically insert angularJS contextMenu on HTML tags
我在我的应用程序中使用这个 angularJS contextMenu 模块,我需要将它动态插入到一些 HTML 标签中。我正在尝试类似的方法,但它不起作用。
e.client.html("<a context-menu=\"menuOptions\">click here</a>");
我已经 menuOptions
在我的作用域上这样声明:
$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);
}
}
];
有人知道怎么做吗?
您需要 angular 来编译您的动态上下文菜单,以便它可以处理 context-menu
指令。最好的方法是:
//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);
希望对您有所帮助。
我在我的应用程序中使用这个 angularJS contextMenu 模块,我需要将它动态插入到一些 HTML 标签中。我正在尝试类似的方法,但它不起作用。
e.client.html("<a context-menu=\"menuOptions\">click here</a>");
我已经 menuOptions
在我的作用域上这样声明:
$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);
}
}
];
有人知道怎么做吗?
您需要 angular 来编译您的动态上下文菜单,以便它可以处理 context-menu
指令。最好的方法是:
//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);
希望对您有所帮助。