DEV Community

[Comment from a deleted post]
Collapse
 
julioflores profile image
Julio R. Flores

Hi David I wonder how to pass data to the Component Modal?

Right now I solved it using the ModalService with a property called "payload", and passed on the open() method. But I don't feel this is the right solution.

The modal would need to have the payload ready or do more things OnInit.

Maybe it's a good idea to have a look in the @angular/material code for the Dialog to see how things works there (by the way they use a Directive approach).

Thank you, nice post 👍

Collapse
 
daviddalbusco profile image
David Dal Busco

Hi Julio,

I am not absolutely sure but, you can maybe pass parameters using the componentRef.

// As in the blog post
this.componentRef = this.componentFactoryResolver
      .resolveComponentFactory<T>(component)
      .create(this.injector);

// Pass values. Something being an Input() of the component.
this.componentRef.instance.something = yourValue;
Enter fullscreen mode Exit fullscreen mode