When I was using ngif, I encountered an issue with getting the element reference of the child component. After extensive searching, I discovered that in order to access the element, I needed to use view children instead of view child. While I am able to get the reference to the child component, I am unable to assign values to the child properties.
In this scenario, `CorrespondenceAddressComponent` is my child component. I am trying to assign values to one of the objects (`AddressComponentMetadataDto`) within the correspondence address component from the `ManagePersonComponent` in the `SetControlsReadModeInPerson` method. However, I keep getting `undefined` when trying to assign values or call methods on the child component.
https://i.stack.imgur.com/fn3wx.png
Code snippet from ManagePersonComponent:
export class ManagePersonComponent extends ManagePartyComponent implements AfterViewInit {
ngAfterViewInit(): void {
this.CurrentPartyType = CurrentPartyTypeEnum.Person;
this.GetInitialDataFromService();
this.SetControlsReadModeInPerson(this.IsReadonly);
}
SetControlsReadModeInPerson(isReadOnly: boolean): void {
this.CorrespondenceAddressComponent.AddressComponentMetadataDto.IsPostalCodeDisabled = isReadOnly;
}
Base component - ManagePartyComponent:
export class ManagePartyComponent extends ProjectPageComponentBase {
@ViewChildren(CorrespondenceAddressComponent) CorrespondenceAddressComponent: CorrespondenceAddressComponent;
}
HTML:
<form #form="ngForm" [ngClass]="{'form-submitted' : form.submitted }" (ngSubmit)="SaveAndNavigate()">
<toolbar [ShowSaveButton]="!IsReadonly"></toolbar>
<p-tabView [(activeIndex)]="SelectedTabIndex">
<p-tabPanel [header]="'Caption.CRM.CorrespondenceAddress' | translate">
<correspondence-address [ParentForm]="form"></correspondence-address>
</p-tabPanel>
</p-tabView>
</form>
CorrespondenceAddressComponent:
export class CorrespondenceAddressComponent extends ProjectPageComponentBase {
AddressComponentMetadataDto= new AddressComponentMetadataDto();
ngOnInit():void {
}
}