Skip to content

Commit a9a0e27

Browse files
gkalpakvicb
authored andcommitted
fix(upgrade): fix empty transclusion content with AngularJS@>=1.5.8 (#22167)
The function provided by `ngUpgrade` as `parentBoundTranscludeFn` when upgrading a component with transclusion, will break in AngularJS v1.5.8+ if no transclusion content is provided. The reason is that AngularJS will try to destroy the transclusion scope (which would not be needed any more). But since the transcluded content comes from Angular, not AngularJS, there is no transclusion scope to destroy. This commit fixes it by providing a dummy scope object with a no-op `$destroy()` method. Fixes #22175 PR Close #22167
1 parent 6638390 commit a9a0e27

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/upgrade/src/common/upgrade_helper.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,15 @@ export class UpgradeHelper {
122122
prepareTransclusion(): angular.ILinkFn|undefined {
123123
const transclude = this.directive.transclude;
124124
const contentChildNodes = this.extractChildNodes();
125+
const attachChildrenFn: angular.ILinkFn = (scope, cloneAttachFn) => {
126+
// Since AngularJS v1.5.8, `cloneAttachFn` will try to destroy the transclusion scope if
127+
// `$template` is empty. Since the transcluded content comes from Angular, not AngularJS,
128+
// there will be no transclusion scope here.
129+
// Provide a dummy `scope.$destroy()` method to prevent `cloneAttachFn` from throwing.
130+
scope = scope || {$destroy: () => undefined};
131+
return cloneAttachFn !($template, scope);
132+
};
125133
let $template = contentChildNodes;
126-
let attachChildrenFn: angular.ILinkFn|undefined = (scope, cloneAttach) =>
127-
cloneAttach !($template, scope);
128134

129135
if (transclude) {
130136
const slots = Object.create(null);

0 commit comments

Comments
 (0)