From 8eede099cd8aa6d524d1de385d08432072fd294e Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Fri, 18 Jul 2014 11:12:54 -0700 Subject: [PATCH] perf(ngBindHtml): move addClass to the compile phase Closes #8261 Conflicts: src/ng/directive/ngBind.js --- src/ng/directive/ngBind.js | 23 ++++++++++++++++------- test/ng/directive/ngBindSpec.js | 8 ++++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/ng/directive/ngBind.js b/src/ng/directive/ngBind.js index 2e7c7ffa9e0f..15bd0755889d 100644 --- a/src/ng/directive/ngBind.js +++ b/src/ng/directive/ngBind.js @@ -177,14 +177,23 @@ var ngBindTemplateDirective = ['$interpolate', function($interpolate) { */ 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)) || ''); + }); + }; + } }; }]; diff --git a/test/ng/directive/ngBindSpec.js b/test/ng/directive/ngBindSpec.js index 7af4c13f2b63..67eb9f7e835a 100644 --- a/test/ng/directive/ngBindSpec.js +++ b/test/ng/directive/ngBindSpec.js @@ -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('
'); + $compile(element); + expect(element.hasClass('ng-binding')).toBe(true); + })); + + describe('SCE disabled', function() { beforeEach(function() { module(function($sceProvider) { $sceProvider.enabled(false); });