Skip to content

Commit 17084a0

Browse files
author
Niels Dequeker
committed
Merge pull request angular-ui-tree#460 from angular-ui-tree/fix-empty-placeholder
Fix empty placeholder
2 parents 331bec3 + a458c8d commit 17084a0

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

source/controllers/treeCtrl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
};
3434

3535
this.resetEmptyElement = function () {
36-
if ($scope.$nodesScope.$modelValue.length === 0 &&
36+
if ((!$scope.$nodesScope.$modelValue || $scope.$nodesScope.$modelValue.length === 0) &&
3737
$scope.emptyPlaceholderEnabled) {
3838
$element.append($scope.$emptyElm);
3939
} else {

source/directives/uiTree.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
scope.$watch(attrs.emptyPlaceholderEnabled, function (val) {
4343
if ((typeof val) == 'boolean') {
4444
scope.emptyPlaceholderEnabled = val;
45+
ctrl.resetEmptyElement();
4546
}
4647
});
4748

source/directives/uiTree.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,19 @@
4646

4747
var element = createElement('<div ui-tree empty-placeholder-enabled="enableEmptyPlaceholder"><div ui-tree-nodes="" ng-model="items"></div></div>');
4848
expect(element.scope().emptyPlaceholderEnabled).toEqual(true);
49+
expect(element.scope().$emptyElm.parent()).toEqual(element);
4950

5051
$scope.enableEmptyPlaceholder = false;
5152
$scope.$digest();
5253

5354
expect(element.scope().emptyPlaceholderEnabled).toEqual(false);
55+
expect(element.scope().$emptyElm.parent()).toNotEqual(element);
56+
});
57+
58+
it('should hide the empty placeholder when ui-tree, ui-tree-nodes and empty-placeholder-enabled="false" are on the same element', function () {
59+
var element = createElement('<div ui-tree empty-placeholder-enabled="false" ui-tree-nodes="" ng-model="items"></div>');
60+
expect(element.scope().emptyPlaceholderEnabled).toEqual(false);
61+
expect(element.scope().$emptyElm.parent()).toNotEqual(element);
5462
});
5563

5664
it('should allow enabling / disabling dropping nodes', function () {

0 commit comments

Comments
 (0)