angular/angular · error · RuntimeError

VIEW_DESTROYED_INSERT_ERROR

VIEW_DESTROYED_INSERT_ERROR

Error message

Cannot insert a destroyed View in a ViewContainer!

What it means

Error "Cannot insert a destroyed View in a ViewContainer!" thrown in angular/angular.

Source

Thrown at packages/core/src/linker/view_container_ref.ts:551

      ) {
        return null;
      }

      return parentTNode?.namespace ?? null;
    }

    return this._hostTNode.namespace;
  }

  override insert(viewRef: ViewRef, index?: number): ViewRef {
    return this.insertImpl(viewRef, index, true);
  }

  private insertImpl(viewRef: ViewRef, index?: number, addToDOM?: boolean): ViewRef {
    const lView = (viewRef as R3ViewRef<any>)._lView!;

    if (ngDevMode && viewRef.destroyed) {
      throw new RuntimeError(
        RuntimeErrorCode.VIEW_DESTROYED_INSERT_ERROR,
        ngDevMode && 'Cannot insert a destroyed View in a ViewContainer!',
      );
    }

    if (viewAttachedToContainer(lView)) {
      // If view is already attached, detach it first so we clean up references appropriately.

      const prevIdx = this.indexOf(viewRef);

      // A view might be attached either to this or a different container. The `prevIdx` for
      // those cases will be:
      // equal to -1 for views attached to this ViewContainerRef
      // >= 0 for views attached to a different ViewContainerRef
      if (prevIdx !== -1) {
        this.detach(prevIdx);
      } else {
        const prevLContainer = lView[PARENT] as LContainer;

View on GitHub (pinned to 51cb07e980)

Solutions

  1. Do not insert a destroyed view; create a new embedded view instead.

When it happens

Trigger: Thrown at packages/core/src/linker/view_container_ref.ts:551 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of angular/angular@51cb07e980 (2026-08-22). Data as JSON: /api/errors/ae70a96fe44d3789. Report an issue: GitHub.