Task
In the shopping cart, there is a list of items with options, quantities, and prices. The goal is to calculate the total price based on any changes in the quantity and option of an item.
Investigation I included [(ngModel)] for 2-way data binding, but for some reason, the page keeps loading and then crashes without any error message. Removing the ngModel attribute allows the page to load successfully.
<span class="price col-1 pull-right" >{{ orderType*price}}</span>
<div class="qty" style="margin:0;">
<span class="spinner">
<span class="sub">-</span>
<input type="number" id="qty" name="qty" min="1" max="100"
value="1" class="qty-spinner" [(ngModel)]="quantity" />
<span class="add">+</span>
</span>
</div>
<div class="type">
<label class="radio inline" *ngFor="let option of item.options; let k = index">
<input id="{{'toggle-half-'+item.id+'-'+j}}" type="radio"
name="{{'option-toggle-'+item.id+'-'+j}}" [value]="option.value"
[checked]='k===0' [(ngModel)]="orderType" />
<span>{{option.title}} </span>
</label>
</div>
TypeScript Implementation
quantity:number;
orderType:number;
price:number;
constructor() {
this.quantity = 1;
this.price = 0;
}
Controls Utilized
1) Number Control with input type number for quantity input.
2) Radio Controls for Options [Half/Full]
3) Span element for displaying the calculated price.
Desired Outcome
The current price, set at 0, should update when either the quantity or option is modified.
Example values for option [Half] = 10
Example values for option [Full] = 20
Please provide guidance on how to execute this. Is the above logic and implementation correct?
Thank you in advance