fix(ngBindHtml): clear contents when model is falsy

Closes #864
This commit is contained in:
Igor Minar 2012-04-08 02:49:03 -07:00
parent dc7b764d4d
commit 10daefc6f4
2 changed files with 18 additions and 4 deletions

View file

@ -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 || '');
});
});
@ -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 || '');
});
}
}];

View file

@ -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('');
});
}));
});