Skip to content

Commit 498115d

Browse files
authored
Merge pull request #141 from hieutranagi47/compile_html_string
Add an option to compile html string to help user can add html string with their custom directives.
2 parents 61ec34c + 04a0194 commit 498115d

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ Every menu option is represented by an Object containing the following propertie
9494
| -------- | ---- | ----------- |
9595
| text | Function/String | A function that returns the string or the actual string itself. Either text or html must be specified |
9696
| html | Function/String | A function or string that returns the html to be used for this menu option. Either text or html must be specified |
97+
| compile | Boolean | To compile html string to use a custom directive in the html string |
9798
| click | Function | The function to be called on click of the option|
9899
| enabled | Function/Boolean | A function returning whether the option is enabled or not, or a boolean |
99100
| displayed | Function/Boolean | A function returning whether the option is displayed or not, or a boolean. If not displayed, no element is created at all and nothing related to the item will be executed (events, functions returning children, etc.) |

contextMenu.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
// Triggers right after any context menu is opened
2424
ContextMenuOpened: 'context-menu-opened'
2525
})
26-
.directive('contextMenu', ['$rootScope', 'ContextMenuEvents', '$parse', '$q', 'CustomService', '$sce', '$document', '$window',
27-
function ($rootScope, ContextMenuEvents, $parse, $q, custom, $sce, $document, $window) {
26+
.directive('contextMenu', ['$rootScope', 'ContextMenuEvents', '$parse', '$q', 'CustomService', '$sce', '$document', '$window', '$compile',
27+
function ($rootScope, ContextMenuEvents, $parse, $q, custom, $sce, $document, $window, $compile) {
2828

2929
var _contextMenus = [];
3030
// Contains the element that was clicked to show the context menu
@@ -50,8 +50,13 @@
5050
// runs the function that expects a jQuery/jqLite element
5151
optionText = item.html($scope);
5252
} else {
53-
// Assumes that the developer already placed a valid jQuery/jqLite element
54-
optionText = item.html;
53+
// Incase we want to compile html string to initialize their custom directive in html string
54+
if (item.compile) {
55+
optionText = $compile(item.html)($scope);
56+
} else {
57+
// Assumes that the developer already placed a valid jQuery/jqLite element
58+
optionText = item.html;
59+
}
5560
}
5661
} else {
5762

0 commit comments

Comments
 (0)