@angular/core#StaticProvider TypeScript Examples

The following examples show how to use @angular/core#StaticProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: golden-layout-component.service.ts    From golden-layout-ng-app with MIT License 6 votes vote down vote up
createComponent(componentTypeJsonValue: JsonValue, container: ComponentContainer) {
    const componentType = this._componentTypeMap.get(componentTypeJsonValue as string);
    if (componentType === undefined) {
      throw new Error('Unknown component type')
    } else {
      const provider: StaticProvider = { provide: BaseComponentDirective.GoldenLayoutContainerInjectionToken, useValue: container };
      const injector = Injector.create({
        providers: [provider]
      });
      const componentFactoryRef = this.componentFactoryResolver.resolveComponentFactory<BaseComponentDirective>(componentType);
      return componentFactoryRef.create(injector);
    }
  }
Example #2
Source File: message-dialog.component.ts    From dev-manager-desktop with Apache License 2.0 6 votes vote down vote up
ngAfterViewInit(): void {
    if (this.message instanceof Type) {
      const componentFactory = this.componentFactoryResolver.resolveComponentFactory(this.message);
      this.messageComponent.clear();
      let providers: StaticProvider[] = [];
      if (this.messageExtras) {
        providers = Object.getOwnPropertyNames(this.messageExtras).map(name => ({ provide: name, useValue: this.messageExtras[name] }));
      }
      this.messageComponent.createComponent(componentFactory, null, Injector.create({ providers }));
      this.changeDetector.detectChanges();
    }
  }
Example #3
Source File: platform-miniprogram.ts    From angular-miniprogram with MIT License 6 votes vote down vote up
export function platformMiniProgram<T>(
  extraProviders: StaticProvider[] = [],
  app?: T
) {
  return createPlatformFactory(platformCore, 'miniProgram', [
    { provide: APP_TOKEN, useValue: MiniProgramCore.loadApp(app || {}) },
    {
      provide: MINIPROGRAM_GLOBAL_TOKEN,
      useValue: MiniProgramCore.MINIPROGRAM_GLOBAL,
    },
  ])(extraProviders);
}