perf(ngBindHtml): move addClass to the compile phase
Closes #8261 Conflicts: src/ng/directive/ngBind.js
This commit is contained in:
@@ -177,14 +177,23 @@ var ngBindTemplateDirective = ['$interpolate', function($interpolate) {
|
||||
</example>
|
||||
*/
|
||||
var ngBindHtmlDirective = ['$sce', '$parse', function($sce, $parse) {
|
||||
return function(scope, element, attr) {
|
||||
element.addClass('ng-binding').data('$binding', attr.ngBindHtml);
|
||||
return {
|
||||
compile: function (tElement) {
|
||||
tElement.addClass('ng-binding');
|
||||
|
||||
var parsed = $parse(attr.ngBindHtml);
|
||||
function getStringValue() { return (parsed(scope) || '').toString(); }
|
||||
return function (scope, element, attr) {
|
||||
element.data('$binding', attr.ngBindHtml);
|
||||
|
||||
scope.$watch(getStringValue, function ngBindHtmlWatchAction(value) {
|
||||
element.html($sce.getTrustedHtml(parsed(scope)) || '');
|
||||
});
|
||||
var parsed = $parse(attr.ngBindHtml);
|
||||
|
||||
function getStringValue() {
|
||||
return (parsed(scope) || '').toString();
|
||||
}
|
||||
|
||||
scope.$watch(getStringValue, function ngBindHtmlWatchAction(value) {
|
||||
element.html($sce.getTrustedHtml(parsed(scope)) || '');
|
||||
});
|
||||
};
|
||||
}
|
||||
};
|
||||
}];
|
||||
|
||||
@@ -68,6 +68,14 @@ describe('ngBind*', function() {
|
||||
|
||||
|
||||
describe('ngBindHtml', function() {
|
||||
|
||||
it('should add ng-binding class to the element in compile phase', inject(function($compile) {
|
||||
var element = jqLite('<div ng-bind-html="myHtml"></div>');
|
||||
$compile(element);
|
||||
expect(element.hasClass('ng-binding')).toBe(true);
|
||||
}));
|
||||
|
||||
|
||||
describe('SCE disabled', function() {
|
||||
beforeEach(function() {
|
||||
module(function($sceProvider) { $sceProvider.enabled(false); });
|
||||
|
||||
Reference in New Issue
Block a user