What's the best way to reset a child's component state in Angular? E.g. resetting a child's form.
I've developed 5 possible solutions:
- Child listens to a primitive value (boolean) that it receives via @Input. Using setTimeout, otherwise the change is too fast and the child will not register. See scenario 3 in StackBlitz.
- Passing an observable to a child component. Scenario 4 on StackBlitz
- Using a complex data structure (object). If you create a new object every time, the child will think it's completely different, thus being able to correctly trigger it's reset form function. Scenario 5 on StackBlitz
- ViewChild. Scenario 6 on StackBlitz
- Creating the formControl on the parent and passing it down to the child. Scenario 7 on StackBlitz
https://stackblitz.com/github/laurensdewaele/parent-child-angular-react/tree/master/angular-example