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

perf(ngBindHtml): move addClass to the compile phase #8261

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/ng/directive/ngBind.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +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, tAttrs) {
tElement.addClass('ng-binding');

var parsed = $parse(attr.ngBindHtml);
var changeDetector = $parse(attr.ngBindHtml, function getStringValue(value) {
return function (scope, element, attr) {
element.data('$binding', attr.ngBindHtml);
var parsed = $parse(attr.ngBindHtml);
var changeDetector = $parse(attr.ngBindHtml, function getStringValue(value) {
return (value || '').toString();
});

scope.$watch(changeDetector, function ngBindHtmlWatchAction() {
// we re-evaluate the expr because we want a TrustedValueHolderType
// for $sce, not a string
element.html($sce.getTrustedHtml(parsed(scope)) || '');
});
};
scope.$watch(changeDetector, function ngBindHtmlWatchAction() {
// we re-evaluate the expr because we want a TrustedValueHolderType
// for $sce, not a string
element.html($sce.getTrustedHtml(parsed(scope)) || '');
});
};
}
}
}];
8 changes: 8 additions & 0 deletions test/ng/directive/ngBindSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,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); });
Expand Down