【问题标题】:How can we retain ngx-datepicker values in angular 8我们如何在角度 8 中保留 ngx-datepicker 值
【发布时间】:2020-12-16 19:55:34
【问题描述】:

我们如何在 ngModel 更改时保留 ngx-bootstrap 日期选择器的值,

<input type="text"
       placeholder="Daterangepicker"
       [value]="date"
       class="form-control"
      bsDaterangepicker>

在我的ts中

date = new Date(); 

【问题讨论】:

    标签: angular datepicker ngx-bootstrap


    【解决方案1】:

    很遗憾,我无法从您提供的ts 中得到明确的想法,但这是一个您可能会从中受益的示例:

    HTML:

    <input type="text" 
           class="form-control" 
           bsDatepicker [bsValue]="bsValue" 
           [(ngModel)]="student.dateOfBirth" 
    />
    

    ts:

    show(studentId?: number): void {
            this._studentService.getStudentFor(studentId).subscribe(studentResult => {
                this.bsValue = moment(this.student.dateOfBirth, 'YYYY-MM-DD').toDate();
                this.active = true;
                this.modal.show();
            });
        }
    

    【讨论】:

    • 为什么同时使用 bsvalue 和 ngmodel?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-30
    • 1970-01-01
    相关资源
    最近更新 更多