當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript ApplicationRef.attachView方法代碼示例

本文整理匯總了TypeScript中@angular/core.ApplicationRef.attachView方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript ApplicationRef.attachView方法的具體用法?TypeScript ApplicationRef.attachView怎麽用?TypeScript ApplicationRef.attachView使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@angular/core.ApplicationRef的用法示例。


在下文中一共展示了ApplicationRef.attachView方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: open

  open(moduleCFR: ComponentFactoryResolver, contentInjector: Injector, content: any, options): DrawerRef {
    const containerSelector = options.container || 'body';
    const containerEl = document.querySelector(containerSelector);

    if (!containerEl) {
      throw new Error(`The specified drawer container "${containerSelector}" was not found in the DOM.`);
    }

    const activeDrawer = new ActiveDrawer();
    const contentRef = this._getContentRef(moduleCFR, contentInjector, content, activeDrawer);

    let drawerCmptRef: ComponentRef<DrawerComponent>;
    let backdropCmptRef: ComponentRef<DrawerBackdropComponent>;
    let drawerRef: DrawerRef;

    if (options.backdrop !== false) {
      backdropCmptRef = this._backdropFactory.create(this._injector);
      this._applicationRef.attachView(backdropCmptRef.hostView);
      containerEl.appendChild(backdropCmptRef.location.nativeElement);
    }
    drawerCmptRef = this._drawerFactory.create(this._injector, contentRef.nodes);
    this._applicationRef.attachView(drawerCmptRef.hostView);
    containerEl.appendChild(drawerCmptRef.location.nativeElement);

    drawerRef = new DrawerRef(drawerCmptRef, contentRef, backdropCmptRef);

    activeDrawer.close = (result: any) => { drawerRef.close(result); };
    activeDrawer.dismiss = (reason: any) => { drawerRef.dismiss(reason); };

    this.applyDrawerOptions(drawerCmptRef.instance, options);

    return drawerRef;
  }
開發者ID:marlonprudente,項目名稱:composer,代碼行數:33,代碼來源:drawer-stack.ts

示例2: open

  open(moduleCFR: ComponentFactoryResolver, contentInjector: Injector, content: any, options): NgbModalRef {
    const containerSelector = options.container || 'body';
    const containerEl = document.querySelector(containerSelector);

    if (!containerEl) {
      throw new Error(`The specified modal container "${containerSelector}" was not found in the DOM.`);
    }

    const activeModal = new NgbActiveModal();
    const contentRef = this._getContentRef(moduleCFR, contentInjector, content, activeModal);

    let windowCmptRef: ComponentRef<NgbModalWindow>;
    let backdropCmptRef: ComponentRef<NgbModalBackdrop>;
    let ngbModalRef: NgbModalRef;


    if (options.backdrop !== false) {
      backdropCmptRef = this._backdropFactory.create(this._injector);
      this._applicationRef.attachView(backdropCmptRef.hostView);
      containerEl.appendChild(backdropCmptRef.location.nativeElement);
    }
    windowCmptRef = this._windowFactory.create(this._injector, contentRef.nodes);
    this._applicationRef.attachView(windowCmptRef.hostView);
    containerEl.appendChild(windowCmptRef.location.nativeElement);

    ngbModalRef = new NgbModalRef(windowCmptRef, contentRef, backdropCmptRef);

    activeModal.close = (result: any) => { ngbModalRef.close(result); };
    activeModal.dismiss = (reason: any) => { ngbModalRef.dismiss(reason); };

    this._applyWindowOptions(windowCmptRef.instance, options);

    return ngbModalRef;
  }
開發者ID:Chenlevin,項目名稱:ng-bootstrap,代碼行數:34,代碼來源:modal-stack.ts

示例3: Promise

        return new Promise((resolve, reject) => {
            const location = this.getRootViewContainerNode();
            const componentFactory = this.componentFactoryResolver.resolveComponentFactory(dialogType);
            const componentRef = componentFactory.create(this.injector);
            const componentRootNode = this.getComponentRootNode(componentRef);

            this.applicationRef.attachView(componentRef.hostView);
            componentRef.onDestroy(() => {
                this.applicationRef.detachView(componentRef.hostView);
            });

            location.appendChild(componentRootNode);

            const instance = componentRef.instance as DynamicDialog;
            instance.nativeElement = componentRootNode;
            instance.options = options;
            instance.closed.subscribe(() => {
                componentRef.destroy();
            });
            instance.confirm.subscribe((value: any) => {
                resolve(value);
            }, (error: any) => {
                reject(error);
            });
            instance.cancel.subscribe(() => {
                if (onCancel) {
                    onCancel();
                }
            });
        });
開發者ID:Gitjerryzhong,項目名稱:bell-tm-static,代碼行數:30,代碼來源:dialog.ts

示例4:

  /**
   * Attach the given ComponentPortal to DOM element using the ComponentFactoryResolver.
   * @param portal Portal to be attached
   */
  attachComponentPortal<T>(portal: ComponentPortal<T>, newestOnTop: boolean): ComponentRef<T> {
    const componentFactory = this._componentFactoryResolver.resolveComponentFactory(portal.component);
    let componentRef: ComponentRef<T>;

    // If the portal specifies a ViewContainerRef, we will use that as the attachment point
    // for the component (in terms of Angular's component tree, not rendering).
    // When the ViewContainerRef is missing, we use the factory to create the component directly
    // and then manually attach the ChangeDetector for that component to the application (which
    // happens automatically when using a ViewContainer).
    componentRef = componentFactory.create(portal.injector);

    // When creating a component outside of a ViewContainer, we need to manually register
    // its ChangeDetector with the application. This API is unfortunately not yet published
    // in Angular core. The change detector must also be deregistered when the component
    // is destroyed to prevent memory leaks.
    this._appRef.attachView(componentRef.hostView);

    this.setDisposeFn(() => {
      this._appRef.detachView(componentRef.hostView);
      componentRef.destroy();
    });

    // At this point the component has been instantiated, so we move it to the location in the DOM
    // where we want it to be rendered.
    if (newestOnTop) {
      this._hostDomElement.insertBefore(this._getComponentRootNode(componentRef), this._hostDomElement.firstChild);
    } else {
      this._hostDomElement.appendChild(this._getComponentRootNode(componentRef));
    }

    return componentRef;
  }
開發者ID:Shivk355,項目名稱:mywork,代碼行數:36,代碼來源:dom-portal-host.ts

示例5:

  /**
   * Attach the given ComponentPortal to DOM element using the ComponentFactoryResolver.
   * @param portal Portal to be attached
   * @returns Reference to the created component.
   */
  attachComponentPortal<T>(portal: ComponentPortal<T>): ComponentRef<T> {
    let componentFactory = this._componentFactoryResolver.resolveComponentFactory(portal.component);
    let componentRef: ComponentRef<T>;

    // If the portal specifies a ViewContainerRef, we will use that as the attachment point
    // for the component (in terms of Angular's component tree, not rendering).
    // When the ViewContainerRef is missing, we use the factory to create the component directly
    // and then manually attach the view to the application.
    if (portal.viewContainerRef) {
      componentRef = portal.viewContainerRef.createComponent(
          componentFactory,
          portal.viewContainerRef.length,
          portal.injector || portal.viewContainerRef.parentInjector);

      this.setDisposeFn(() => componentRef.destroy());
    } else {
      componentRef = componentFactory.create(portal.injector || this._defaultInjector);
      this._appRef.attachView(componentRef.hostView);
      this.setDisposeFn(() => {
        this._appRef.detachView(componentRef.hostView);
        componentRef.destroy();
      });
    }
    // At this point the component has been instantiated, so we move it to the location in the DOM
    // where we want it to be rendered.
    this.outletElement.appendChild(this._getComponentRootNode(componentRef));

    return componentRef;
  }
開發者ID:OkBayat,項目名稱:material2,代碼行數:34,代碼來源:dom-portal-outlet.ts

示例6: initPopup

    private initPopup({data, coord, component, onCloseCallback}: IPopupParam): void {
        this.componentRef = this.componentFactoryResolver.resolveComponentFactory<DynamicPopup>(component).create(this.injector);
        const popupComponent = this.componentRef.instance;
        const domElem = (this.componentRef.hostView as EmbeddedViewRef<DynamicPopup>).rootNodes[0] as HTMLElement;

        this.bindInputProps(popupComponent, data, coord);
        this.bindOutputProps(popupComponent, domElem, onCloseCallback);
        this.renderer.addClass(domElem, 'popup');
        this.renderer.appendChild((this.appRef.components[0].location).nativeElement, domElem);
        this.appRef.attachView(this.componentRef.hostView);
    }
開發者ID:young891221,項目名稱:pinpoint,代碼行數:11,代碼來源:dynamic-popup.service.ts

示例7: _getContentRef

 private _getContentRef(
     moduleCFR: ComponentFactoryResolver, contentInjector: Injector, content: any,
     context: NgbActiveModal): ContentRef {
   if (!content) {
     return new ContentRef([]);
   } else if (content instanceof TemplateRef) {
     const viewRef = content.createEmbeddedView(context);
     this._applicationRef.attachView(viewRef);
     return new ContentRef([viewRef.rootNodes], viewRef);
   } else if (isString(content)) {
     return new ContentRef([[document.createTextNode(`${content}`)]]);
   } else {
     const contentCmptFactory = moduleCFR.resolveComponentFactory(content);
     const modalContentInjector =
         ReflectiveInjector.resolveAndCreate([{provide: NgbActiveModal, useValue: context}], contentInjector);
     const componentRef = contentCmptFactory.create(modalContentInjector);
     this._applicationRef.attachView(componentRef.hostView);
     return new ContentRef([[componentRef.location.nativeElement]], componentRef.hostView, componentRef);
   }
 }
開發者ID:Chenlevin,項目名稱:ng-bootstrap,代碼行數:20,代碼來源:modal-stack.ts

示例8: new

 /** 動態構建組件 */
 protected build<T>(component: { new(...args: any[]): T; }): ComponentRef<T> {
     let componentFactory = this.resolver.resolveComponentFactory(component);
     let componentRef = componentFactory.create(this.injector);
     let componentRootNode = (componentRef.hostView as EmbeddedViewRef<any>).rootNodes[0] as HTMLElement;
     this.applicationRef.attachView(componentRef.hostView);
     componentRef.onDestroy(() => {
         this.applicationRef.detachView(componentRef.hostView);
     });
     document.body.appendChild(componentRootNode);
     return componentRef;
 }
開發者ID:cwl19870312,項目名稱:mwyapp,代碼行數:12,代碼來源:base-ui.service.ts

示例9: new

 public appendComponentToBody<T>(component: {
   new (...args): T;
 }): ComponentRef<T> {
   const componentRef = this.componentFactoryResolver
     .resolveComponentFactory<T>(component)
     .create(this.injector);
   this.appRef.attachView(componentRef.hostView);
   const domElem = (componentRef.hostView as EmbeddedViewRef<T>)
     .rootNodes[0] as HTMLElement;
   this.appendToDom(domElem);
   return componentRef;
 }
開發者ID:bitpay,項目名稱:copay,代碼行數:12,代碼來源:dom.ts

示例10: onCreated

    return this.zone.run(() => {
      const factory = this.componentFactoryResolver.resolveComponentFactory(type);
      const component = factory.create(this.injector);
      this.appRef.attachView(component.hostView);

      if (onCreated) {
        onCreated(component);
      }

      this.tooltipRef = component;
      return (component.hostView as EmbeddedViewRef<any>).rootNodes[0] as HTMLElement;
    });
開發者ID:Vatsinator,項目名稱:Vatsinator,代碼行數:12,代碼來源:tooltip.service.ts


注:本文中的@angular/core.ApplicationRef.attachView方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。