Submodule 19.3: Angular Components
Components Part 2 ...
Update the menu.component.tsĀ
Update the menu.component.ts
file as follows to move the details of the dishes into a constant, in preparation for introducing services in a future submodule, where we will move these data to a service instead of using these inside ourĀ application:
Note that we have assigned to the exported variable dishes the constant Dishes dishes = DISHES
.
You possibly wonder why we have removed the type for the dishes.
TypeScript is intelligent enough to realize that when we do this it'll automatically assign BOTH the type and values to dishes to match what you have in DISHES.
But if we want to be completely clear, we can also write dishes : Dish[] = DISHES
.
Note also the variable called selectedDish.
We are going to use this variable in this submodule, and in later submodules also.
We make this equal to the first dish in my array selectedDish = DISHES[0]
.
You could also write selectedDish : Dish = DISHES[0])