[英]Setting new value to another model reassign old model (Angular)
I have 2 date pickers in angular HTML我在 angular HTML 中有 2 个日期选择器
here is it就这个
<div *ngIf="receipt.chargeTypeId !== 4" class="row">
<div class="col-6">
<div class="form-group">
<label class="label-title">{{ l('RentalPeriodFrom') }}</label><br />
<utc-datepicker name="RentalPeriodFrom" [(ngModel)]="receipt.rentalPeriodFrom">
</utc-datepicker>
</div>
</div>
<div class="col-6">
<div class="form-group">
<label class="label-title">{{ l('RentalPeriodTo') }}</label><br />
<utc-datepicker name="RentalPeriodTo" [(ngModel)]="receipt.rentalPeriodTo">
</utc-datepicker>
</div>
</div>
</div>
I need to set RentalPeriodTo
to RentalPeriodFrom
+ 1 month我需要将
RentalPeriodTo
设置为RentalPeriodFrom
+ 1 个月
I do it like this我这样做
this.receipt.rentalPeriodFrom = this.tenancyData.tenancyStartDate;
const periodTo = this.receipt.rentalPeriodFrom;
this.receipt.rentalPeriodTo = periodTo.add(1, 'M');
But it changes my this.receipt.rentalPeriodFrom
to date relevant to this.receipt.rentalPeriodTo
但它改变了我的
this.receipt.rentalPeriodFrom
与this.receipt.rentalPeriodTo
相关的日期
Where is the problem?问题出在哪里?
// this might be due to the receipt.rentalPeriodFrom is copied as reference to periodTo which change source when we modify the receiptto // 这可能是由于receipt.rentalPeriodFrom 被复制为引用 periodTo 当我们修改receiptto 时更改源
this.receipt.rentalPeriodFrom = this.tenancyData.tenancyStartDate;
const periodTo = Object.assign({},this.receipt.rentalPeriodFrom);
this.receipt.rentalPeriodFrom;
this.receipt.rentalPeriodTo = periodTo.add(1, 'M');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.