perf(ngBindHtml): move addClass to the compile phase

Closes #8261

Conflicts:
	src/ng/directive/ngBind.js
This commit is contained in:
Igor Minar
2014-07-18 11:12:54 -07:00
parent a17d42d706
commit 8eede099cd
2 changed files with 24 additions and 7 deletions
+16 -7
View File
@@ -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
View File
@@ -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); });