#contextMenu
AngularJS UI Bootstrap Module for adding context menus to elements. Demo
Add a reference to contextMenu.js
. In your app config add ui.bootstrap.contextMenu
as a dependency module.
<div>
<div ng-repeat="item in items" context-menu="menuOptions">Right Click: {{item.name}}</div>
</div>
<div ng-bind="selected"></div>
$scope.selected = 'None';
$scope.items = [
{ name: 'John', otherProperty: 'Foo' },
{ name: 'Joe', otherProperty: 'Bar' }
};
$scope.menuOptions = [
['Select', function ($itemScope) {
$scope.selected = $itemScope.item.name;
}],
null, // Dividier
['Remove', function ($itemScope) {
$scope.items.splice($itemScope.$index, 1);
}]
];
Every menu option has an array with 2 indexs. Most items will use the [String, Function]
format. If you need a dynamic item in your context menu you can also use the [Function, Function]
format.
$scope.menuOptions = [
[function ($itemScope) { return $itemScope.item.name; }, function ($itemScope) {
// Code
}]
];
Nested lists are not supported yet, because I have not needed it yet. If you add it please do a pull request.
$scope.menuOptions = [
['Parent Item 1', function ($itemScope) {
// Code
}, ['Child Item 1', function ($itemScope) {
// Code
}],
['Child Item 2', function ($itemScope) {
// Code
}]
]
];