2

Good afternoon,

I am trying to create a dynamic template to display information from a dynamic component as listed in the NPM readme. https://www.npmjs.com/package/angular5-toaster

Example :

import {BodyOutputType} from 'angular5-toaster';

@Component({
  selector: 'dynamic-component',
  template: `<div>loaded via component</div>`
})
class DynamicComponent { }

var toast : Toast = {
    type: 'error',
    title: 'Title text',
    body: DynamicComponent,
    bodyOutputType: BodyOutputType.Component
};

this.toasterService.pop(toast);

My question is how would i pass parameters into the DynamicComponent.

Thanks

user1403598
  • 485
  • 1
  • 6
  • 21

1 Answers1

0

I would suggest to share the data using Angular Service.

Step 1 : set the data want to pass in to the dynamic component before you load the Toast.

    this.someService.data="some parameter"
    this.toasterService.pop(toast);

Step 2 : Once the component initialize you can read the value by injecting the service as a dependency on your dynamic component.

ngOnInit(){
//read the data
console.log(this.someService.data)
}
Jameel Moideen
  • 7,542
  • 12
  • 51
  • 79