I have a simple Angular Material selection list with some values inside it.
My requirement is to calculate the sum of the selected (checked) values only (and after that, apply a discount to the price, if it exceeds some amount).
I believe it must be easy, but I am new to Angular and Material components, and somehow cannot find what I want on Google or here... My code is as below:
HTML
<mat-selection-list #options>
<mat-list-option *ngFor="let option of optionArray">
{{option.name}} - ${{option.price}}
</mat-list-option>
</mat-selection-list>
<p>
You have selected {{options.selectedOptions.selected.length}} items with total sum of $ {{ }}. </p>
<p *ngIf="">
Your discount is 10%. </p>
TS
interface Options {
name: string;
price: number;
}
optionArray: Options[] = [
{
name: 'Item 1',
price: 4000
},
{
name: 'Item 2',
price: 8000
},
{
name: 'Item 3',
price: 3500
},
{
name: 'Item 4',
price: 500
}
]
Thank you in advance!