How to bind value to the array of object based on date selection in angular8

最后都变了- 提交于 2020-03-04 23:28:58

问题


i have array of objects, here if the date is picked from the datetime calender, the value is not binding to that object, but if i change the date manually then it works, but if i select from calendar then the value is nit binding. I have tried with (change) and (ngModelChange), but both didnt work.

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


回答1:


Try this:

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


来源:https://stackoverflow.com/questions/60088398/how-to-bind-value-to-the-array-of-object-based-on-date-selection-in-angular8

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!