public open(modalInstance: SkyModalInstance, component: any, providers?: any[]) {
    let factory = this.resolver.resolveComponentFactory(component);
    let hostService = new SkyModalHostService();

    providers = providers || [];

    providers.push({
      provide: SkyModalHostService,
      useValue: hostService
    });

    let resolvedProviders = ReflectiveInjector.resolve(providers);

    let injector = ReflectiveInjector.fromResolvedProviders(resolvedProviders, this.injector);

    let modalComponentRef = this.target.createComponent(factory, undefined, injector);

    modalInstance.componentInstance = modalComponentRef.instance;

    function closeModal() {
      hostService.destroy();
      modalComponentRef.destroy();
    }

    hostService.close.subscribe((modalComponent: SkyModalComponent) => {
      closeModal();
    });

    modalInstance.setCloseCallback(() => {
      closeModal();
    });
  }
Example #2
0
  return async(): Promise<BootstrapResponse> => {

    try {
      deferredLog('info', 'Bootstrapping server');
      const resolvedProviders: ProviderType[] = await Promise.all(CORE_PROVIDERS.concat(providers));

      //initialize all bootstrappers (in order they need to be created)
      const resolvedBootstrappers: EntityBootstrapper[] = [
        new ModelBootstrapper,
        new ServiceBootstrapper,
        new MigrationBootstrapper,
        new SeederBootstrapper,
        new ControllerBootstrapper,
      ];

      const bootrapperProviders: any[] = resolvedBootstrappers.reduce((result: any[], bootstrapper: EntityBootstrapper) => {
        return result.concat(bootstrapper.getInjectableEntities());
      }, []);

      const mergedProviders = ReflectiveInjector.resolve(bootrapperProviders.concat(resolvedProviders));

      const injector = ReflectiveInjector.fromResolvedProviders(mergedProviders);

      logger = injector.get(Logger)
        .source('bootstrap');

      // iterate over any logs that have been deferred
      deferredLogs.forEach((log: DeferredLog) => {
        logger[log.level](...log.messages);
      });
      deferredLogs = []; //clear buffer

      // iterate over all of the resolved bootstrappers, invoking the bootstrap to initialize the
      // entities. iteration is completed in serial so that bootstrappers that depend on other
      // entities won't invoke until those other entities are finished intializing
      await resolvedBootstrappers.reduce(async(current: Promise<void>, next: EntityBootstrapper): Promise<void> => {

        await current;

        return Promise.resolve(next.setInjector(injector).invokeBootstrap());

      }, Promise.resolve()); //initial value
      // get vars for the bootstrapper
      const server: Server = injector.get(Server);

      let response = {injector, server, logger};

      if (afterBootstrap) {
        await afterBootstrap(response);
        // await Promise.resolve(afterBootstrap(response));
        return response;
      }

      return response;
    } catch (e) {
      handleBootstrapError(e, logger);
    }

  }
Example #3
0
 appendTopOfLocation(ComponentClass, location: ViewContainerRef, providers?: ResolvedReflectiveProvider[]): ComponentRef<any> {
   let componentFactory = this.componentFactoryResolver.resolveComponentFactory(ComponentClass);
   let parentInjector = location.parentInjector;
   let childInjector: Injector = parentInjector;
   if (providers && providers.length > 0) {
     childInjector = ReflectiveInjector.fromResolvedProviders(providers, parentInjector);
   }
   return location.createComponent(componentFactory, 0, childInjector);
 }
            .then(cmpFactory => {
                const vcr = this._viewContainer,
                    bindings = this._compileConfig.bindings,
                    ctxInjector = vcr.parentInjector;

                const childInjector = Array.isArray(bindings) && bindings.length > 0 ?
                    ReflectiveInjector.fromResolvedProviders(bindings, ctxInjector) : ctxInjector;
                return this.dialog.contentRef =
                    vcr.createComponent(cmpFactory, vcr.length, childInjector);
            });
Example #5
0
			this._cr.resolveComponent(TooltipComponent).then((cmpFactory: ComponentFactory<TooltipComponent>) => {
				// Create reflective injector to provide an instance of TooltipData 
				let providers = ReflectiveInjector.resolve([
					{ provide: TooltipData, useValue: new TooltipData(el, text, align) },
				]);
				let injector = ReflectiveInjector.fromResolvedProviders(providers, this.viewContainer.parentInjector);

				// Create the component, outputs a promise...
				return this.viewContainer.createComponent(cmpFactory, this.viewContainer.length, injector);
			}).then((cmpRef: ComponentRef<TooltipComponent>) => {
      .then((componentFactory:ComponentFactory<T>) => {
        const viewContainerRef = _viewContainerRef || this.getRootViewContainerRef();
        let bindings = ReflectiveInjector.resolve([
          new Provider(ComponentOptionsClass, {useValue: options})
        ]);
        const ctxInjector = viewContainerRef.parentInjector;

        const childInjector = Array.isArray(bindings) && bindings.length > 0 ?
          ReflectiveInjector.fromResolvedProviders(bindings, ctxInjector) : ctxInjector;
        return viewContainerRef.createComponent(componentFactory, viewContainerRef.length, childInjector);
      });
  /**
   * Creates an instance of a Component and attaches it to the View Container found at the
   * `location` specified as {@link ViewContainerRef}.
   *
   * You can optionally provide `providers` to configure the {@link Injector} provisioned for this
   * Component Instance.
   *
   * Returns {@link ComponentRef} representing the newly created Component.
   * @param ComponentClass - @Component class
   * @param location - reference to the location
   * @param providers - optional array of providers
   * @returns {ComponentRef<T>} - returns ComponentRef<T>
   */
  public appendNextToLocation<T>(ComponentClass:Type<T>,
                                 location:ViewContainerRef,
                                 providers?:ResolvedReflectiveProvider[]):ComponentRef<T> {
    let componentFactory = this.componentFactoryResolver.resolveComponentFactory(ComponentClass);
    let parentInjector = location.parentInjector;
    let childInjector: Injector = parentInjector;
    if (providers && providers.length > 0) {
      childInjector = ReflectiveInjector.fromResolvedProviders(providers, parentInjector);
    }

    return location.createComponent(componentFactory, location.length, childInjector);
  }
      .then(factory => {
        // Create Injector for Component
        const injector = ReflectiveInjector.fromResolvedProviders([], this.vcRef.parentInjector);

        // Create Component with factory and injector. 0 = index which determines where in the
        // container the component will be rendered. 0 means it will be rendered starting at the
        // beginning
        const componentRef = this.vcRef.createComponent(factory, 0, injector, []);

        // Define any parameters you want to pass to the newly generated component
        componentRef.instance.item = this.item;
      });
Example #9
0
 ngOnInit() {
     //ValueProvider { provide: any; useValue: any;}
     // let providers = [{ provide: "item", useValue: this.item }, { provide: "column", useValue: this.column }];
     // let inputs = ReflectiveInjector.resolve(providers);
     let injector = ReflectiveInjector.fromResolvedProviders([], this.vcRef.parentInjector);
     let component;
     if (this.column.cell) {
         let factory = this.resolver.resolveComponentFactory(this.column.cell);
         component = factory.create(injector);
     } else {
         let factory = this.resolver.resolveComponentFactory(DefaultCellComponent);
         component = factory.create(injector);
     }
     component.instance.column = this.column;
     component.instance.item = this.item;
     this.vcRef.insert(component.hostView);
 }
  public open(modalInstance: SkyModalInstance, component: any, config?: IConfig) {
    let params: IConfig = Object.assign({}, config);
    let factory = this.resolver.resolveComponentFactory(component);
    let hostService = new SkyModalHostService();
    let adapter = this.adapter;

    params.providers.push({
      provide: SkyModalHostService,
      useValue: hostService
    });
    params.providers.push({
      provide: SkyModalConfiguation,
      useValue: params
    });

    adapter.setPageScroll(SkyModalHostService.openModalCount > 0);

    let providers = params.providers /* istanbul ignore next */ || [];
    let resolvedProviders = ReflectiveInjector.resolve(providers);
    let injector = ReflectiveInjector.fromResolvedProviders(resolvedProviders, this.injector);
    let modalComponentRef = this.target.createComponent(factory, undefined, injector);

    modalInstance.componentInstance = modalComponentRef.instance;

    function closeModal() {
      hostService.destroy();
      adapter.setPageScroll(SkyModalHostService.openModalCount > 0);
      modalComponentRef.destroy();
    }

    hostService.close.subscribe((modalComponent: SkyModalComponent) => {
      closeModal();
    });

    modalInstance.setCloseCallback(() => {
      closeModal();
    });
  }
function getInjector(viewContainer: ViewContainerRef, bindings: ResolvedReflectiveProvider[]) {
  const ctxInjector = viewContainer.parentInjector;
  return Array.isArray(bindings) && bindings.length > 0 ?
    ReflectiveInjector.fromResolvedProviders(bindings, ctxInjector) : ctxInjector;

}
					componentFactory => {
						let injector = ReflectiveInjector.fromResolvedProviders([], container.injector);
						let component = container.createComponent(componentFactory, 0, injector);
						resolve(component);
					}
 .then(factory => {
   const injector = ReflectiveInjector.fromResolvedProviders([],
                                     this.viewContainerRef.parentInjector);
   this.viewContainerRef.createComponent(factory, 0, injector, []);
 });
 .then(cmpFactory => {
   const ctxInjector = viewContainer.parentInjector;
   const childInjector = Array.isArray(bindings) && bindings.length > 0 ?
     ReflectiveInjector.fromResolvedProviders(bindings, ctxInjector) : ctxInjector;
   return viewContainer.createComponent(cmpFactory, viewContainer.length, childInjector);
 })
Example #15
0
 /**
  * Same as [createVariety] but resolves providers ahead of time.
  */
 function createVarietyResolved() {
   for (var i = 0; i < iterations; ++i) {
     ReflectiveInjector.fromResolvedProviders(variousProvidersResolved);
   }
 }