Angular: Pass data from Material Dialog to component, which didn't open the dialog

前端 未结 3 858
陌清茗
陌清茗 2020-12-12 02:56

I have a network.component which opens my dialog send-tx-dialog.component. The user fills the send-tx-dialog with information. I want to send that information to another com

3条回答
  •  盖世英雄少女心
    2020-12-12 03:42

    In your shared service you can do:

    public transaction = new Subject();
    
    emitTransaction(val) {
      this.transaction.next(val);
    }
    

    And after your subribe of the closed dialog do:

    dialogRef.afterClosed().subscribe(
          data => this.sharedService.emitTransaction(data);
        );
    

    And in your other component:

    this.sharedService.transaction.subscribe(transaction => {
        this.transaction = transaction;
      })
    

    It should look something like this.

提交回复
热议问题