In this exercise, you will practice using Angular signals to manage an array of numbers. Each number in the array will be tied to a dynamic CounterComponent
, where the parent component will maintain the overall state of the array.
You will create a signal to hold an array of numbers. Each number will be passed to a separate CounterComponent
. The main app will also handle updates from the child components and update the array when needed.
Each CounterComponent
will receive the number from the parent via an input
. The component will render increment and decrement buttons and emit the updated value back to the parent when these buttons are clicked.
- Use
input
andoutput
but do not use a model in this case (do you know why?)
- Create a signal to hold an array of numbers, e.g.,
[0, 5, 10]
. - Dynamically render a
CounterComponent
for each number in the array using@for
. - Pass each number to the child component via an
input.required
. - When the child component emits a new value, update the corresponding value in the array using the signal's
update
method and immutable operators.
- Use
input.required
to accept the current number from the parent. - Render two buttons to increment and decrement the number.
- Use
output
to emit the updated number back to the parent component when the buttons are clicked.