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

Commit 35358fd

Browse files
IgorMinarrodyhaddad
authored andcommitted
perf($compile): move ng-binding class stamping for interpolation into compile phase
1 parent fd5f389 commit 35358fd

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/ng/compile.js

+20-12
Original file line numberDiff line numberDiff line change
@@ -1847,18 +1847,26 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
18471847
if (interpolateFn) {
18481848
directives.push({
18491849
priority: 0,
1850-
compile: valueFn(function textInterpolateLinkFn(scope, node) {
1851-
var parent = node.parent(),
1852-
bindings = parent.data('$binding') || [];
1853-
// Need to interpolate again in case this is using one-time bindings in multiple clones
1854-
// of transcluded templates.
1855-
interpolateFn = $interpolate(text);
1856-
bindings.push(interpolateFn);
1857-
safeAddClass(parent.data('$binding', bindings), 'ng-binding');
1858-
scope.$watch(interpolateFn, function interpolateFnWatchAction(value) {
1859-
node[0].nodeValue = value;
1860-
});
1861-
})
1850+
compile: function textInterpolateCompileFn(templateNode) {
1851+
// when transcluding a template that has bindings in the root
1852+
// then we don't have a parent and should do this in the linkFn
1853+
var parent = templateNode.parent(), hasCompileParent = parent.length;
1854+
if (hasCompileParent) safeAddClass(templateNode.parent(), 'ng-binding');
1855+
1856+
return function textInterpolateLinkFn(scope, node) {
1857+
var parent = node.parent(),
1858+
bindings = parent.data('$binding') || [];
1859+
// Need to interpolate again in case this is using one-time bindings in multiple clones
1860+
// of transcluded templates.
1861+
interpolateFn = $interpolate(text);
1862+
bindings.push(interpolateFn);
1863+
parent.data('$binding', bindings);
1864+
if (!hasCompileParent) safeAddClass(parent, 'ng-binding');
1865+
scope.$watch(interpolateFn, function interpolateFnWatchAction(value) {
1866+
node[0].nodeValue = value;
1867+
});
1868+
};
1869+
}
18621870
});
18631871
}
18641872
}

0 commit comments

Comments
 (0)