loadDetached<T> method

  1. @mustCallSuper
ComponentRef<T> loadDetached<T>(
  1. ComponentFactory<T> component,
  2. {Injector injector}
)

Creates and loads a new instance of the component defined by component.

Returns a ComponentRef that is detached from the physical DOM, and may be manually manipulated in order to be attached to DOM by the user. This API is considered to be a lower-level hook for higher-level components such as popups.

May optionally define a parent injector; defaults to an empty injector.

// An `ExampleComponent`s generated code, including a `ComponentFactory`.
import 'example.template.dart' as ng;

class AdBannerComponent implements AfterViewInit {
  final ComponentLoader _loader;

  AdBannerComponent(this._loader);

  @override
  ngAfterViewInit() {
    final component = _loader.loadDetached(ng.ExampleComponentNgFactory);
    // Do something with this reference.
  }
}

See also loadNextToLocation.

Implementation

@mustCallSuper
ComponentRef<T> loadDetached<T>(
  ComponentFactory<T> component, {
  Injector injector,
}) =>
    component.create(injector ?? const Injector.empty());