After running the command ng build --prod
in my project, I encountered the following error message: "Cannot assign to 'total' because it is a constant or read-only property for function get total(){}"
The function causing the issue is:
get total() {
return this.products
.map(p => p.Unit_price * p.Quantity)
.reduce((a, b) => a + b, 0);
}
This is how it is implemented in the HTML:
<form [formGroup]="addsale" (ngSubmit)="onaddsale()" >
<div class="row">
<div class="input-field col s2" style="float: right;">
<label for="total">Total {{total}} ALL</label>
<input formControlName="total" id="total" type="text" class="validate" [value]="total" [(ngModel)]="total">
</div>
<div class="input-field col s2" style="float: right;">
<label for="amount_paid">Amount Paid:</label>
<input formControlName="amount_paid" id="amount_paid" [value]="total" type="text" class="validate" [(ngModel)]="total">
</div>
<div class="input-field col s2" style="float: right;">
<label for="total">Subtotal</label>
<input formControlName="Subtotal" id="Subtotal" type="text" class="validate" [value]="total" [(ngModel)]="total">
</div>
</div>
</form>
The TypeScript form definition is as follows:
this.addsale = this.fb.group({
'amount_paid': new FormControl('', Validators.required),
'Subtotal': new FormControl('', Validators.required),
'total': new FormControl('', Validators.required)
});
If you have any ideas on how to resolve this issue, please let me know. Thank you!