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

Commit

Permalink
fix(ngBindHtml): clear contents when model is falsy
Browse files Browse the repository at this point in the history
Closes #864
  • Loading branch information
IgorMinar committed Apr 9, 2012
1 parent dc7b764 commit 10daefc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/ng/directive/ngBind.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ var ngBindDirective = ngDirective(function(scope, element, attr) {
var ngBindHtmlUnsafeDirective = ngDirective(function(scope, element, attr) {
element.addClass('ng-binding').data('$binding', attr.ngBindHtmlUnsafe);
scope.$watch(attr.ngBindHtmlUnsafe, function(value) {
element.html(value == undefined ? '' : value);
element.html(value || '');
});
});

Expand All @@ -96,9 +96,8 @@ var ngBindHtmlDirective = ['$sanitize', function($sanitize) {
return function(scope, element, attr) {
element.addClass('ng-binding').data('$binding', attr.ngBindHtml);
scope.$watch(attr.ngBindHtml, function(value) {
if (value = $sanitize(value)) {
element.html(value);
}
value = $sanitize(value);
element.html(value || '');
});
}
}];
Expand Down
15 changes: 15 additions & 0 deletions test/ng/directive/ngBindSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ describe('ng-bind-*', function() {
$rootScope.$digest();
expect(lowercase(element.html())).toEqual('<div>hello</div>');
}));


it('should reset html when value is null or undefined', inject(function($compile, $rootScope) {
element = $compile('<div ng-bind-html="html"></div>')($rootScope);

forEach([null, undefined, ''], function(val) {
$rootScope.html = 'some val';
$rootScope.$digest();
expect(lowercase(element.html())).toEqual('some val');

$rootScope.html = val;
$rootScope.$digest();
expect(lowercase(element.html())).toEqual('');
});
}));
});


Expand Down

0 comments on commit 10daefc

Please sign in to comment.