I am new to ngOnchanges and facing below issue.
my parent component is setting recom value on ngOnChanges and sends the same value to child component. child receives the same as input in ngOnChanges. depending on some condition like totalVal>0 i set inputField to true which is initially set to false. if inputField is true i show some component in reactive forms. but when my below structure execute model2Form() it still gets inputField as false. I cant post actual code so just created a structure as per my project as shown below.
Please suggest how do i solve this issue.
// parent component
ngOnchanges(){
this.recom = [{
totalVal: 5000,
monthlydata: true
}]
}
//child component
@Input()
private recom: any;
inputField: boolean = false;
ngOnChanges(){
this.setValue();
this.loadFuture();
}
setValue(){
if(this.recom.totalVal > 0){
this.inputField = true;
}
}
loadFuture(){
}
model2Form(){
//getting input field as false even if i set it as true in setValue()
if(inputField){
this.heroForm.setControl('secretLairs', addressFormArray);
}
}
<!-- parent component>
<parent-comp [recom]="recom"></parent-comp>
<!-- child component -->
<div [FormControlName]="secretLairs"> </div>