如何基于angular8中的日期选择将值绑定到对象数组 [英] How to bind value to the array of object based on date selection in angular8
本文介绍了如何基于angular8中的日期选择将值绑定到对象数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有对象数组,在这里,如果从datetime日历中选取日期,则该值未绑定到该对象,但是如果我手动更改日期,则它起作用,但是如果我从日历中选择,则值为尼特装订.我已经尝试过使用(change)和(ngModelChange),但是都没有用.
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;
});
}
推荐答案
尝试一下:
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");
});
}
这篇关于如何基于angular8中的日期选择将值绑定到对象数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文