user3194721
user3194721

Reputation: 815

Angular 4 kendo Dialog How to read updated values from Dialog

I'm sending 'TotalUnits' value into the Dialog and updating value there. I want to read back 'TotalUnits' value in the 'dialog.result'. Some how I'm not seeing updated value. Any help please?

Main Component:

AllocationDialog(data: any) {
    const dialog: DialogRef = this.component.dialogService.open({
      title: ' Allocations',
      content: AllocationComponent,
      actions: [
        { text: 'Save', primary: true, data },
      ],
      width: 500,
      height: 500
    });
    dialog.result.subscribe((dialogResult) => {
      if (dialogResult instanceof DialogCloseResult) {
        console.log('close');
      } else {
        console.log('action', dialogResult);
      }
    });

    const allocationsInfo = dialog.content.instance;
    allocationsInfo.TotalUnits = data.TotalUnits;
}

AllocationComponent - Dialog:

@Input() public TotalUnits: number;

<input kendoTextBox [(ngModel)]="TotalUnits" />

Upvotes: 3

Views: 1668

Answers (2)

Anshuman Jaiswal
Anshuman Jaiswal

Reputation: 5462

Everything is correct in your code except the statement order. You should access updated data within subscription as:

dialog.result.subscribe((dialogResult) => {
    if (dialogResult instanceof DialogCloseResult) {
        console.log('close');
    } else {
        console.log('action', dialogResult);
    }
    //============= correct place ===============//
    const allocationsInfo = dialog.content.instance;
    allocationsInfo.TotalUnits = data.TotalUnits;
});

Upvotes: 3

elvin
elvin

Reputation: 981

Based on the example they have for the DialogService, you can get back those values with the same instance of the dialog on dialog.content.instance.

dialogRef.result.subscribe((dialogResult) => {
    console.log(dialogRef.content.instance);  // <-- here are your updated values
  if (dialogResult instanceof DialogCloseResult) {
    console.log('close');
  } else {
    console.log('action', dialogResult);
  }
}

I did a copy from the original plunker in the Kendo docs to illustrate it, showing an input box for the age, so you can see the updated object in the console's output.

https://plnkr.co/edit/nVdvbaPPgDrtbIuV57ZG?p=preview

Upvotes: 1

Related Questions