问题
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