【发布时间】:2019-04-10 06:07:13
【问题描述】:
有人能告诉我如何在 Mat-Datepicker 中显示用户保存的日期吗?
最初从 get 服务获取 endDate 为 null(来自嵌套对象的数据,从另一个组件调用)。进入编辑模式时。正在选择值并保存它。在控制台中,它打印选定的日期。但在网络中它变为空。
this.endDate: string;
<mat-form-field>
<input matInput [value] = "endDate" [matDatepicker]="myDatepicker" name="endDate" [(ngModel)]="endDate">
<mat-datepicker-toggle matSuffix [for]="myDatepicker"></mat-datepicker-toggle>
<mat-datepicker #myDatepicker ></mat-datepicker>
</mat-form-field>
在保存方法中:
save(){
let obj = {
endDate = this.endDate; // my ngModel
}
}
updateChange(d){
this.endDate = d; // i can see the changed value here but not able to save
}
保存数据的实际对象
const sample : OriginalModel = {
demoKey : this.sample['key'].demo,
demoKey2 : this.sample['key2'].demo2,
endDate : this.endDate
}
如何在编辑模式下显示用户保存的值?
请分享解决方案/工作堆栈闪电战。
提前致谢
【问题讨论】:
-
你为什么要这样包装你的对象?
-
好吧实际上是用于示例目的的对象的一部分。我的对象会像
const sample : OriginalModel = { demoKey : this.sample['key'].demo, demoKey2 : this.sample['key2'].demo2, endDate : this.endDate }
标签: angular typescript datepicker angular-material