title: Angular Material Dialog: How to update the injected data when they change in the parent component?
body: <p>Injecting data to a material dialog is working well, but how can be a way to automatically update these data if they change in the parent / opener component (coming from a (WAMP) subscription for example)?</p>
  
  <p><strong>[Update]</strong><br>
  I crated a minimal version to try out how the behavior is: <a href="https://stackblitz.com/edit/angular-njh44v?embed=1&amp;file=src/app/app.component.ts" rel="noreferrer">https://stackblitz.com/edit/angular-njh44v?embed=1&amp;file=src/app/app.component.ts</a><br>
  Open the console on the bottom right side and click on the grey box with the numbers. You see that the dialog gets the current number and does no more update after that.<br>
  <strong>[/Update]</strong></p>
  
  <p><strong>[Update 2]</strong><br>
  Based on the second idea of Jusmpty, this seams to work at first sight (even if the dialog shows / updates the first time after data arrive):
  <a href="https://stackblitz.com/edit/angular-thd34f?embed=1&amp;file=src/app/app.component.ts" rel="noreferrer">https://stackblitz.com/edit/angular-thd34f?embed=1&amp;file=src/app/app.component.ts</a><br>
  <strong>[/Update]</strong></p>
  
  <p>The concrete case looks like this:</p>
  
  <ul>
  <li>There is an <em>area</em> component that subscribes to a WAMP service and gets all the <em>data</em> for the including <em>parts</em>. This draws all the <em>parts</em> with an *ngFor.<br>
  File <strong>area.component.ts</strong></li>
  <li>Each <em>part</em> has an own component showing some <em>data</em>. If the <em>data</em> in the subscriptions change, the view is correctly and automatically updated, for each / all <em>parts</em>.<br>
  Files <strong>part.component.ts</strong> and <strong>part.component.html</strong></li>
  <li>On each <em>part</em> a click opens a <em>dialog</em> where more data are showing.<br>
  Files <strong>part-details-dialog.component.ts</strong> and <strong>part-details-dialog.component.html</strong></li>
  </ul>
  
  <p>And on this last action / step occurs the issue where the current data are showing (injecting) but no more updated if something in the subscribed data changes.</p>
  
  <h2>area.component.ts</h2>
  
  <pre class="lang-js prettyprint-override"><code>@Component({
    selector: 'app-area',
    template: '&lt;app-part *ngFor="let part of plan" [partData]="part"&gt;&lt;/app-part&gt;'
  })
  export class AreaComponent {
  
    plan = [];
  
    planasync$ = this.wampService
      .topic('sendplan')
      .subscribe(
        res =&gt; {
          let tm = new TableMap();
          this.plan = tm.tableToMap(res.argskw).filter((m) =&gt; m.area === 1);
        },
        err =&gt; console.log("res err", err),
        () =&gt; console.log("res complete"));
  
    constructor(private wampService: WampService) { }
  }
  </code></pre>
  
  <h2>part.component.ts</h2>
  
  <pre class="lang-js prettyprint-override"><code>import { PartDetailsDialogComponent } from './part-details-dialog/part-details-dialog.component';
  
  @Component({
    selector: 'app-part-details',
    templateUrl: './part.component.html'
  })
  export class PartComponent {
    @Input() partData: any;
  
    constructor(public dialog: MatDialog) {}
  
    openDetailsDialog(): void {
      let dialogRef = this.dialog.open(PartDetailsDialogComponent, {
        width: '650px',
        height: '400px',
        data: {
          partData: this.partData
        }
      });
    }
  }
  </code></pre>
  
  <h2>part.component.html</h2>
  
  <pre class="lang-html prettyprint-override"><code>&lt;mat-card (click)="openDetailsDialog()"&gt;
    &lt;mat-card-title&gt;Nr: {{ partData.partNr }}&lt;/mat-card-title&gt;
    &lt;mat-card-content&gt;
        &lt;div&gt;Current speed: {{ partData.speed }}&lt;/div&gt;
    &lt;/mat-card-content&gt;
  &lt;/mat-card&gt;
  </code></pre>
  
  <h2>part-details-dialog.component.ts</h2>
  
  <pre class="lang-js prettyprint-override"><code>@Component({
    selector: 'app-part-details-dialog',
    templateUrl: './part-details-dialog.component.html'
  })
  export class PartDetailsDialogComponent {
  
    constructor(public dialogRef: MatDialogRef&lt;PartDetailsDialogComponent&gt;, @Inject(MAT_DIALOG_DATA) public data: any) { }
  
    onNoClick(): void {
      this.dialogRef.close();
    }
  }
  </code></pre>
  
  <h2>part-details-dialog.component.html</h2>
  
  <pre class="lang-html prettyprint-override"><code>&lt;h1 mat-dialog-title&gt;Part Details for Nr. {{ data.partData.partNr }}&lt;/h1&gt;
  &lt;div mat-dialog-content&gt;
    &lt;div&gt;Current speed details: {{ data.partData.speed }}&lt;/div&gt;
  &lt;/div&gt;
  &lt;div mat-dialog-actions&gt;
    &lt;button mat-button (click)="onNoClick()"&gt;Cancel&lt;/button&gt;
    &lt;button mat-button [mat-dialog-close]="data.animal" cdkFocusInitial&gt;Ok&lt;/button&gt;
  &lt;/div&gt;
  </code></pre>