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

Commit 903e735

Browse files
committed
perf(ngBindHtml): move addClass to the compile phase
Closes #8261
1 parent 3f4ee15 commit 903e735

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/ng/directive/ngBind.js

+15-10
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,23 @@ var ngBindTemplateDirective = ['$interpolate', function($interpolate) {
177177
</example>
178178
*/
179179
var ngBindHtmlDirective = ['$sce', '$parse', function($sce, $parse) {
180-
return function(scope, element, attr) {
181-
element.addClass('ng-binding').data('$binding', attr.ngBindHtml);
180+
return {
181+
compile: function (tElement, tAttrs) {
182+
tElement.addClass('ng-binding');
182183

183-
var parsed = $parse(attr.ngBindHtml);
184-
var changeDetector = $parse(attr.ngBindHtml, function getStringValue(value) {
184+
return function (scope, element, attr) {
185+
element.data('$binding', attr.ngBindHtml);
186+
var parsed = $parse(attr.ngBindHtml);
187+
var changeDetector = $parse(attr.ngBindHtml, function getStringValue(value) {
185188
return (value || '').toString();
186189
});
187190

188-
scope.$watch(changeDetector, function ngBindHtmlWatchAction() {
189-
// we re-evaluate the expr because we want a TrustedValueHolderType
190-
// for $sce, not a string
191-
element.html($sce.getTrustedHtml(parsed(scope)) || '');
192-
});
193-
};
191+
scope.$watch(changeDetector, function ngBindHtmlWatchAction() {
192+
// we re-evaluate the expr because we want a TrustedValueHolderType
193+
// for $sce, not a string
194+
element.html($sce.getTrustedHtml(parsed(scope)) || '');
195+
});
196+
};
197+
}
198+
}
194199
}];

test/ng/directive/ngBindSpec.js

+8
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ describe('ngBind*', function() {
121121

122122

123123
describe('ngBindHtml', function() {
124+
125+
it('should add ng-binding class to the element in compile phase', inject(function($compile) {
126+
var element = jqLite('<div ng-bind-html="myHtml"></div>');
127+
$compile(element);
128+
expect(element.hasClass('ng-binding')).toBe(true);
129+
}));
130+
131+
124132
describe('SCE disabled', function() {
125133
beforeEach(function() {
126134
module(function($sceProvider) { $sceProvider.enabled(false); });

0 commit comments

Comments
 (0)