Skip to content

Commit c8d06e4

Browse files
eugefmgcrea
authored andcommitted
fix(dropdown): options are null if dropdown with inline sibling template is rendered again after it was previously destroyed
if dropdown has inline sibling template then template is saved to the options during the compile time. After dropdown is destroyed (for example it was inside the modal) and rendered again (modal reopened) - compile for dropdown is not executed and options are null. This causes error "angular TypeError: Cannot set property 'scope' of null" and dropdown loses its template. Solution is to save the template not in the options but in the attributes that are not destroyed.
1 parent 01e9009 commit c8d06e4

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/dropdown/dropdown.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ angular.module('mgcrea.ngStrap.dropdown', ['mgcrea.ngStrap.tooltip'])
109109
scope: true,
110110
compile: function(tElement, tAttrs) {
111111

112-
// Directive options
113-
var options = {};
114-
115112
// Support for inlined template (next sibling)
116113
// It must be fetched before compilation
117114
if (!tAttrs.bsDropdown) {
@@ -120,16 +117,16 @@ angular.module('mgcrea.ngStrap.dropdown', ['mgcrea.ngStrap.tooltip'])
120117
nextSibling = nextSibling.nextSibling;
121118
}
122119
if (nextSibling.classList.contains('dropdown-menu')) {
123-
options.template = nextSibling.outerHTML;
124-
options.templateUrl = undefined;
120+
tAttrs.template = nextSibling.outerHTML;
121+
tAttrs.templateUrl = undefined;
125122
nextSibling.parentNode.removeChild(nextSibling);
126123
}
127124
}
128125

129126
return function postLink(scope, element, attr) {
130127

131128
// Directive options
132-
options.scope = scope;
129+
var options = {scope: scope};
133130
angular.forEach(['template', 'templateUrl', 'controller', 'controllerAs', 'placement', 'container', 'delay', 'trigger', 'keyboard', 'html', 'animation', 'id'], function(key) {
134131
if (angular.isDefined(tAttrs[key])) options[key] = tAttrs[key];
135132
});

0 commit comments

Comments
 (0)