EntryComponents in Module for LazyLoading

后端 未结 4 924
广开言路
广开言路 2020-12-31 03:42

I want to load a modal from a component. In Angular Material documentation is write to add the modal component in entryComponents :

This :

@NgModule         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-31 03:54

    An alternative would be to use TemplateRef. This is especially useful in the case of the Angular Material dialog example above, which support both ComponentType and TemplateRef.

    In the HTML, you can use @Input to pass your data to the component

    
      
    
    

    The TS is very simple and there is no need to worry about the module to be lazy loaded or to use entryComponent.

    @ViewChild("popup") popupRef: TemplateRef;
    
    public handleClick() {
      this.modalService.open(this.popupRef, options);
    }
    

提交回复
热议问题