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

Commit 8eede09

Browse files
committed
perf(ngBindHtml): move addClass to the compile phase
Closes #8261 Conflicts: src/ng/directive/ngBind.js
1 parent a17d42d commit 8eede09

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/ng/directive/ngBind.js

+16-7
Original file line numberDiff line numberDiff line change
@@ -177,14 +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) {
182+
tElement.addClass('ng-binding');
182183

183-
var parsed = $parse(attr.ngBindHtml);
184-
function getStringValue() { return (parsed(scope) || '').toString(); }
184+
return function (scope, element, attr) {
185+
element.data('$binding', attr.ngBindHtml);
185186

186-
scope.$watch(getStringValue, function ngBindHtmlWatchAction(value) {
187-
element.html($sce.getTrustedHtml(parsed(scope)) || '');
188-
});
187+
var parsed = $parse(attr.ngBindHtml);
188+
189+
function getStringValue() {
190+
return (parsed(scope) || '').toString();
191+
}
192+
193+
scope.$watch(getStringValue, function ngBindHtmlWatchAction(value) {
194+
element.html($sce.getTrustedHtml(parsed(scope)) || '');
195+
});
196+
};
197+
}
189198
};
190199
}];

test/ng/directive/ngBindSpec.js

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

6969

7070
describe('ngBindHtml', function() {
71+
72+
it('should add ng-binding class to the element in compile phase', inject(function($compile) {
73+
var element = jqLite('<div ng-bind-html="myHtml"></div>');
74+
$compile(element);
75+
expect(element.hasClass('ng-binding')).toBe(true);
76+
}));
77+
78+
7179
describe('SCE disabled', function() {
7280
beforeEach(function() {
7381
module(function($sceProvider) { $sceProvider.enabled(false); });

0 commit comments

Comments
 (0)