【问题标题】:How to bind value to the array of object based on date selection in angular8如何根据角度 8 中的日期选择将值绑定到对象数组
【发布时间】:2020-02-06 05:45:20
【问题描述】:

我有一个对象数组,如果从日期时间日历中选择日期,则该值不会绑定到该对象,但是如果我手动更改日期,那么它可以工作,但是如果我从日历中选择,那么值是尼特绑定。我尝试过 (change) 和 (ngModelChange),但都没有工作。

HTML:

<div class="col-6 
            *ngFor="let restrictValue of Restrictions;let i = index">

            <div class="form-group">
              <input type="text" class="form-control onlyDateTime" placeholder="MM/DD/YYYY HH:MM AM/PM"
                [disabled]="!restrictValue.boolValue" [(ngModel)]="restrictValue.datetime" (change)="dateRestriction($event,restrictValue)" (click)="dateRestriction($event, i)"
                [ngModelOptions]="{standalone: true}" >
            </div>
          </div>

TS:

dateRestriction(event,restriction) {
       $('.onlyDateTime').datetimepicker();
      $('.onlyDate').datetimepicker({
        format: 'L'
      });
   $('.onlyDateTime').datetimepicker(
    ).on('dp.change', (e)=>{
      const date = e.date;

      });
  }

DEMO

【问题讨论】:

  • @Chellappan from this demo,我不应该启用今天之前的日期,可以处理吗?
  • @Chellappan 我需要你的帮助

标签: angular ngmodel


【解决方案1】:

试试这个:

dateRestriction(event, restriction) {
    $(".onlyDateTime").datetimepicker();
    $(".onlyDate").datetimepicker({ format: "L" });
    $(".onlyDateTime")
      .datetimepicker()
      .on("dp.change", e => {
        const date = e.date;
        this.Restrictions[restriction].datetime = date.format("DD/MM/YYYY HH:mm:ss A");
      });
  }

【讨论】:

  • 这里 am/pm fomat 根据要求也是必需的
  • 那个formArray问题怎么样,今天能解决吗?
  • 我不知道我会检查确定~!
  • 是的,如果解决了,我可以继续我的其他事情,对不起,谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-19
  • 2023-04-10
  • 2020-06-07
  • 1970-01-01
  • 1970-01-01
  • 2019-03-10
相关资源
最近更新 更多