Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
This site is no longer updated.Head to Angular.devHome
/

This is the archived documentation for Angular v17. Please visit angular.dev to see this page for the current version of Angular.

NgModuleRef

Represents an instance of an NgModule created by an NgModuleFactory. Provides access to the NgModule instance and related objects.

      
      abstract class NgModuleRef<T> {
  abstract injector: EnvironmentInjector
  abstract componentFactoryResolver: ComponentFactoryResolver
  abstract instance: T
abstract destroy(): void
abstract onDestroy(callback: () => void): void }

Properties

Property Description
abstract injector: EnvironmentInjector Read-Only

The injector that contains all of the providers of the NgModule.

abstract componentFactoryResolver: ComponentFactoryResolver Read-Only

The resolver that can retrieve component factories in a context of this module.

Note: since v13, dynamic component creation via ViewContainerRef.createComponent does not require resolving component factory: component class can be used directly.

Deprecated Angular no longer requires Component factories. Please use other APIs where Component class can be used directly.

abstract instance: T Read-Only

The NgModule instance.

Methods

Destroys the module instance and all of the data structures associated with it.

      
      abstract destroy(): void
    
Parameters

There are no parameters.

Returns

void

Registers a callback to be executed when the module is destroyed.

      
      abstract onDestroy(callback: () => void): void
    
Parameters
callback () => void
Returns

void