Skip to content
This repository was archived by the owner on Feb 15, 2026. It is now read-only.

Commit 8d5e708

Browse files
committed
codelab: create selectable controls with Material
1 parent f9ebb73 commit 8d5e708

3 files changed

Lines changed: 10 additions & 66 deletions

File tree

src/app/shop/shop.component.html

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -22,53 +22,11 @@
2222
<mat-card-title>Fillings</mat-card-title>
2323
<mat-card-content>
2424
<!-- TODO: #7. Create selectable controls with Angular Material -->
25-
<ul>
26-
<li>
27-
<input type="checkbox" name="vegan" id="vegan"
28-
[(ngModel)]="fillings.bokchoy"
29-
[(ngModel)]="fillings.tofu">
30-
<label for="tall">Vegan</label>
31-
<ul>
32-
<li>
33-
<input type="checkbox"
34-
id="bokchoy"
35-
[(ngModel)]="fillings.bokchoy"
36-
name="bokchoy">
37-
<label for="bokchoy">Bok Choy</label>
38-
</li>
39-
<li>
40-
<input type="checkbox"
41-
id="tofu"
42-
[(ngModel)]="fillings.tofu"
43-
name="tofu">
44-
<label for="tofu">Tofu & Shitake</label>
45-
</li>
46-
</ul>
47-
</li>
48-
<li>
49-
<input type="checkbox"
50-
[(ngModel)]="fillings.chicken"
51-
[(ngModel)]="fillings.impossible"
52-
name="meat" id="meat">
53-
<label for="meat">Meat</label>
54-
<ul>
55-
<li>
56-
<input type="checkbox"
57-
id="chicken"
58-
[(ngModel)]="fillings.chicken"
59-
name="chicken">
60-
<label for="chicken">Chicken</label>
61-
</li>
62-
<li>
63-
<input type="checkbox"
64-
id="impossible"
65-
[(ngModel)]="fillings.impossible"
66-
name="impossible">
67-
<label for="impossible">Impossible Meat</label>
68-
</li>
69-
</ul>
70-
</li>
71-
</ul>
25+
<mat-selection-list [(ngModel)]="selectedFillings" aria-label="Dumpling fillings">
26+
<mat-list-option *ngFor="let flavor of fillings" [value]="flavor" color="primary">
27+
{{ flavor }}
28+
</mat-list-option>
29+
</mat-selection-list>
7230
</mat-card-content>
7331
</mat-card>
7432
<mat-card class="quantity selection-card">

src/app/shop/shop.component.scss

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,6 @@
6262
flex-grow: 1;
6363

6464
// TODO: #7. Create selectable controls with Angular Material
65-
ul {
66-
list-style: none;
67-
margin: 5px 20px;
68-
padding: 0;
69-
}
70-
71-
li {
72-
margin: 10px 0;
73-
}
7465
}
7566

7667
.quantity {

src/app/shop/shop.component.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,8 @@ export class ShopComponent implements OnInit {
2525
color = 'gold';
2626

2727
// TODO: #7. Create selectable controls with Angular Material
28-
fillings = {
29-
bokchoy: true,
30-
tofu: true,
31-
chicken: false,
32-
impossible: false,
33-
};
28+
fillings: string[] = ['Bok Choy & Chili Crunch', 'Tofu & Mushroom', 'Chicken & Ginger', 'Impossible Meat & Spinach'];
29+
selectedFillings: string[] = [];
3430

3531
// TODO: #11. Announce changes with LiveAnnouncer
3632
constructor() { }
@@ -49,10 +45,9 @@ export class ShopComponent implements OnInit {
4945
let flavor = '';
5046

5147
// TODO: #7. Create selectable controls with Angular Material
52-
if (this.fillings.bokchoy) { flavor += 'Bok Choy '; }
53-
if (this.fillings.tofu) { flavor += 'Tofu & Mushroom '; }
54-
if (this.fillings.chicken) { flavor += 'Chicken & Ginger '; }
55-
if (this.fillings.impossible) { flavor += 'Impossible Meat '; }
48+
this.selectedFillings.forEach(filling => {
49+
flavor = flavor + ' ' + filling;
50+
});
5651

5752
const fakePurchase = `Purchase ${this.quantity} ${flavor}dumplings in the color ${this.color}!`;
5853
console.log(fakePurchase);

0 commit comments

Comments
 (0)