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

Commit

Permalink
perf(ngBindHtml): move addClass to the compile phase
Browse files Browse the repository at this point in the history
Closes #8261

Conflicts:
	src/ng/directive/ngBind.js
  • Loading branch information
IgorMinar committed Jul 18, 2014
1 parent a17d42d commit 8eede09
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/ng/directive/ngBind.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) || '');
});
};
}
};
}];
8 changes: 8 additions & 0 deletions test/ng/directive/ngBindSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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); });
Expand Down

0 comments on commit 8eede09

Please sign in to comment.