Skip to content

Commit 7e45a77

Browse files
author
Niels Dequeker
committed
Merge pull request angular-ui-tree#574 from pineconellc/fix_empty_modelvalue_watch
Fix crashing $nodesScope.$modelValue.length watch
2 parents b22c727 + b75913f commit 7e45a77

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"jasmine": true,
23
"bitwise": true,
34
"immed": true,
45
"newcap": true,

source/directives/uiTree.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
scope.$emptyElm.addClass(config.emptyTreeClass);
2626
}
2727

28-
scope.$watch('$nodesScope.$modelValue.length', function () {
29-
if (!scope.$nodesScope.$modelValue) {
28+
scope.$watch('$nodesScope.$modelValue.length', function (val) {
29+
if (!angular.isNumber(val)) {
3030
return;
3131
}
3232

source/directives/uiTree.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,29 @@
108108

109109
expect(element.scope().dragDelay).toEqual(84);
110110
});
111+
112+
describe('$nodesScope', function () {
113+
var controller;
114+
115+
beforeEach(function () {
116+
$scope.items.push('item1');
117+
createElement();
118+
controller = element.controller('uiTree');
119+
spyOn(controller, 'resetEmptyElement');
120+
});
121+
122+
it('should reset empty elements', function () {
123+
$scope.items.pop();
124+
$scope.$digest();
125+
expect(controller.resetEmptyElement).toHaveBeenCalled();
126+
});
127+
128+
it('should not attempt to reset elements without a $nodesScope', function () {
129+
element.scope().$nodesScope = null;
130+
$scope.$digest();
131+
expect(controller.resetEmptyElement).not.toHaveBeenCalled();
132+
});
133+
});
111134
});
112135

113136
}());

0 commit comments

Comments
 (0)