Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 10daefc

Browse files
committed
fix(ngBindHtml): clear contents when model is falsy
Closes #864
1 parent dc7b764 commit 10daefc

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/ng/directive/ngBind.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ var ngBindDirective = ngDirective(function(scope, element, attr) {
7373
var ngBindHtmlUnsafeDirective = ngDirective(function(scope, element, attr) {
7474
element.addClass('ng-binding').data('$binding', attr.ngBindHtmlUnsafe);
7575
scope.$watch(attr.ngBindHtmlUnsafe, function(value) {
76-
element.html(value == undefined ? '' : value);
76+
element.html(value || '');
7777
});
7878
});
7979

@@ -96,9 +96,8 @@ var ngBindHtmlDirective = ['$sanitize', function($sanitize) {
9696
return function(scope, element, attr) {
9797
element.addClass('ng-binding').data('$binding', attr.ngBindHtml);
9898
scope.$watch(attr.ngBindHtml, function(value) {
99-
if (value = $sanitize(value)) {
100-
element.html(value);
101-
}
99+
value = $sanitize(value);
100+
element.html(value || '');
102101
});
103102
}
104103
}];

test/ng/directive/ngBindSpec.js

+15
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,21 @@ describe('ng-bind-*', function() {
8282
$rootScope.$digest();
8383
expect(lowercase(element.html())).toEqual('<div>hello</div>');
8484
}));
85+
86+
87+
it('should reset html when value is null or undefined', inject(function($compile, $rootScope) {
88+
element = $compile('<div ng-bind-html="html"></div>')($rootScope);
89+
90+
forEach([null, undefined, ''], function(val) {
91+
$rootScope.html = 'some val';
92+
$rootScope.$digest();
93+
expect(lowercase(element.html())).toEqual('some val');
94+
95+
$rootScope.html = val;
96+
$rootScope.$digest();
97+
expect(lowercase(element.html())).toEqual('');
98+
});
99+
}));
85100
});
86101

87102

0 commit comments

Comments
 (0)