I created a very simple example for you where poller.service will recieve and store the data and then dialog component can subscribe to that data.
@Component({
selector: 'confirmation-dialog',
templateUrl: 'confirmation-dialog.html',
})
export class ConfirmationDialog {
message: string = "Are you sure?"
confirmButtonText = "Yes"
cancelButtonText = "Cancel"
dataSub: any;
constructor(
@Inject(MAT_DIALOG_DATA) private data: any,
private pollerService: PollerService,
private dialogRef: MatDialogRef<ConfirmationDialog>
) {
this.dataSub = this.pollerService.data.subscribe((data: any) => this.message = data)
if(data) {
this.message = data.message || this.message;
if (data.buttonText) {
this.confirmButtonText = data.buttonText.ok || this.confirmButtonText;
this.cancelButtonText = data.buttonText.cancel || this.cancelButtonText;
}
}
}
onConfirmClick(): void {
this.dialogRef.close(true);
}
}
@Injectable()
export class PollerService {
data: BehaviorSubject<string> = new BehaviorSubject('123');
array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
constructor() {
for(var i = 0; i < this.array.length; i++) {
this.delay(i)
}
}
delay(i: number) {
setTimeout(() => {
console.log(this.array[i])
this.data.next('I am some data changing ' + i)
}, 1000 * i);
}
}
https://stackblitz.com/edit/mat-dialog-example-yta2ir?file=app%2Fconfirmation-dialog.component.ts