diff --git a/packages/core/schematics/ng-generate/control-flow-migration/util.ts b/packages/core/schematics/ng-generate/control-flow-migration/util.ts index 4725888f919..9027de82fb9 100644 --- a/packages/core/schematics/ng-generate/control-flow-migration/util.ts +++ b/packages/core/schematics/ng-generate/control-flow-migration/util.ts @@ -432,8 +432,12 @@ export function getMainBlock(etm: ElementToMigrate, tmpl: string, offset: number // removable containers are ng-templates or ng-containers that no longer need to exist // post migration if (isRemovableContainer(etm)) { - const {childStart, childEnd} = etm.getChildSpan(offset); - return {start: '', middle: tmpl.slice(childStart, childEnd), end: ''}; + let middle = ''; + if (etm.hasChildren()) { + const {childStart, childEnd} = etm.getChildSpan(offset); + middle = tmpl.slice(childStart, childEnd); + } + return {start: '', middle, end: ''}; } else if (isI18nTemplate(etm, i18nAttr)) { // here we're removing an ng-template used for control flow and i18n and // converting it to an ng-container with i18n diff --git a/packages/core/schematics/test/control_flow_migration_spec.ts b/packages/core/schematics/test/control_flow_migration_spec.ts index 0256d343d7f..9051853233e 100644 --- a/packages/core/schematics/test/control_flow_migration_spec.ts +++ b/packages/core/schematics/test/control_flow_migration_spec.ts @@ -2391,6 +2391,45 @@ describe('control flow migration', () => { 'template: `
Option 1
} @case (2) {Option 2
} @default {Option 3
}}