diff --git a/src/dropdown/docs/demo.html b/src/dropdown/docs/demo.html
index c58117de1f..27e5e4a7ed 100644
--- a/src/dropdown/docs/demo.html
+++ b/src/dropdown/docs/demo.html
@@ -14,7 +14,7 @@
-
diff --git a/src/dropdown/dropdown.js b/src/dropdown/dropdown.js
index c7a24bd7db..53a3c36e23 100644
--- a/src/dropdown/dropdown.js
+++ b/src/dropdown/dropdown.js
@@ -112,22 +112,28 @@ angular.module('ui.bootstrap.dropdown', [])
return;
}
- element.bind('click', function(event) {
+ var toggleDropdown = function(event) {
event.preventDefault();
event.stopPropagation();
- if ( !element.hasClass('disabled') && !element.prop('disabled') ) {
+ if ( !element.hasClass('disabled') && !attrs.disabled ) {
scope.$apply(function() {
dropdownCtrl.toggle();
});
}
- });
+ };
+
+ element.bind('click', toggleDropdown);
// WAI-ARIA
element.attr({ 'aria-haspopup': true, 'aria-expanded': false });
scope.$watch(dropdownCtrl.isOpen, function( isOpen ) {
element.attr('aria-expanded', !!isOpen);
});
+
+ scope.$on('$destroy', function() {
+ element.unbind('click', toggleDropdown);
+ });
}
};
});
diff --git a/src/dropdown/test/dropdown.spec.js b/src/dropdown/test/dropdown.spec.js
index a0a4c51f72..eceb6bfcb0 100644
--- a/src/dropdown/test/dropdown.spec.js
+++ b/src/dropdown/test/dropdown.spec.js
@@ -91,6 +91,35 @@ describe('dropdownToggle', function() {
expect(elm.hasClass('open')).toBe(false);
});
+ it('should not toggle if the element has `ng-disabled` as true', function() {
+ $rootScope.isdisabled = true;
+ var elm = $compile('')($rootScope);
+ $rootScope.$digest();
+ elm.find('div').click();
+ expect(elm.hasClass('open')).toBe(false);
+
+ $rootScope.isdisabled = false;
+ $rootScope.$digest();
+ elm.find('div').click();
+ expect(elm.hasClass('open')).toBe(true);
+ });
+
+ it('should unbind events on scope destroy', function() {
+ var $scope = $rootScope.$new();
+ var elm = $compile('')($scope);
+ $scope.$digest();
+
+ var buttonEl = elm.find('button');
+ buttonEl.click();
+ expect(elm.hasClass('open')).toBe(true);
+ buttonEl.click();
+ expect(elm.hasClass('open')).toBe(false);
+
+ $scope.$destroy();
+ buttonEl.click();
+ expect(elm.hasClass('open')).toBe(false);
+ });
+
// issue 270
it('executes other document click events normally', function() {
var checkboxEl = $compile('')($rootScope);