【问题标题】:Angular 4 kendo Dialog How to read updated values from DialogAngular 4 kendo Dialog 如何从 Dialog 读取更新的值
【发布时间】:2018-04-14 12:18:11
【问题描述】:

我将“TotalUnits”值发送到对话框并在那里更新值。我想读回“dialog.result”中的“TotalUnits”值。有些我没有看到更新的价值。请问有什么帮助吗?

主要组件:

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 - 对话框:

@Input() public TotalUnits: number;

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

【问题讨论】:

    标签: angular kendo-ui


    【解决方案1】:

    除了语句顺序之外,您的代码中的所有内容都是正确的。您应该通过以下方式访问订阅中的更新数据:

    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;
    });
    

    【讨论】:

      【解决方案2】:

      根据他们为DialogService 提供的示例,您可以使用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);
        }
      }
      

      我从 Kendo 文档中的原始 plunker 复制了一份来说明它,显示了年龄的输入框,因此您可以在控制台的输出中看到更新后的对象。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-05-11
        • 1970-01-01
        • 2018-05-20
        • 2021-11-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多