'Angular initializing form with @Input value becomes undefined on refresh
I am passing a value from my parent component to my child component using the @Input() communication method. This value is used to initialize the form.
Parent Component.html
<child [someValue]="this.randomValue"></child>
Child Component.ts
@Input() someValue: any;
form: FormGroup;
ngOnInit(){
this.form = this.fb.group(
value: this.fb.array([someValue])
}
someValuebecomes undefined when page reloads... why?- Is there a way to make sure it's not undefined?
- I tried to add this initialize the form in
ngOnChangeswhich solves this problem however leads to unexpected results... such as it will always set theFormArrayto this value and won't let additional values be added to theFormArray
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
