{"record":{"id":"ae70a96fe44d3789","repo":"angular/angular","slug":"view-destroyed-insert-error","errorCode":"VIEW_DESTROYED_INSERT_ERROR","errorMessage":"Cannot insert a destroyed View in a ViewContainer!","messagePattern":"Cannot insert a destroyed View in a ViewContainer!","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"packages/core/src/linker/view_container_ref.ts","lineNumber":551,"sourceCode":"      ) {\n        return null;\n      }\n\n      return parentTNode?.namespace ?? null;\n    }\n\n    return this._hostTNode.namespace;\n  }\n\n  override insert(viewRef: ViewRef, index?: number): ViewRef {\n    return this.insertImpl(viewRef, index, true);\n  }\n\n  private insertImpl(viewRef: ViewRef, index?: number, addToDOM?: boolean): ViewRef {\n    const lView = (viewRef as R3ViewRef<any>)._lView!;\n\n    if (ngDevMode && viewRef.destroyed) {\n      throw new RuntimeError(\n        RuntimeErrorCode.VIEW_DESTROYED_INSERT_ERROR,\n        ngDevMode && 'Cannot insert a destroyed View in a ViewContainer!',\n      );\n    }\n\n    if (viewAttachedToContainer(lView)) {\n      // If view is already attached, detach it first so we clean up references appropriately.\n\n      const prevIdx = this.indexOf(viewRef);\n\n      // A view might be attached either to this or a different container. The `prevIdx` for\n      // those cases will be:\n      // equal to -1 for views attached to this ViewContainerRef\n      // >= 0 for views attached to a different ViewContainerRef\n      if (prevIdx !== -1) {\n        this.detach(prevIdx);\n      } else {\n        const prevLContainer = lView[PARENT] as LContainer;","sourceCodeStart":533,"sourceCodeEnd":569,"githubUrl":"https://github.com/angular/angular/blob/51cb07e98081ab7e4e84a9e0949266a8e19cca84/packages/core/src/linker/view_container_ref.ts#L533-L569","documentation":"Error \"Cannot insert a destroyed View in a ViewContainer!\" thrown in angular/angular.","triggerScenarios":"Thrown at packages/core/src/linker/view_container_ref.ts:551 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Do not insert a destroyed view; create a new embedded view instead."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"51cb07e98081ab7e4e84a9e0949266a8e19cca84","analyzedAt":"2026-08-22T07:04:54.531Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}