As someone who is new to building ionic angular applications (coming from a PHP background), I am currently facing an issue. I have a page with the following code:
export class LicencesTabPage implements OnInit {
public licencesData: any[] | void;
constructor(
protected licenceService: LicencesService,
protected authService: AuthenticationService,
protected modelController: ModalController,
public conversions: DatetimeConversions,
) {
}
async ngOnInit() {
this.getData();
}
async openDetailedModel(index) {
const modal = await this.modelController.create({
component: LicencesDetailedComponent,
componentProps: {
itemDetail: this.licencesData[index]
}
});
modal.onDidDismiss().then((modelData) => {
this.getData();
if (modelData !== null) {
}
});
return await modal.present();
}
protected async getData() {
const userUUID = await this.authService.getStoredUuid();
await this.licenceService.getLicences(userUUID).then(res => {
this.licencesData = JSON.parse(JSON.stringify(res));
});
}
}
Users can access a model component by using the openDetailedModel method. Here is the modal component:
export class LicencesDetailedComponent implements OnInit {
@Input()
public itemDetail: any = [];
protected returnValue: any;
public editItem = false;
// Other declarations omitted for brevity
}
Users can call the updateLicence() method which updates data within the LicencesCommonFunction class. Here is a simplified version of the LicencesCommonFunction class:
export class LicencesCommonFunction implements OnInit {
public newItem: any;
protected licencesService: LicencesService;
// Constructor and other methods omitted for brevity
/**
*
* @param form
*/
updateLicence(form: NgForm) {
this.licencesService.updateLicence(this.newItem).then(() => {
this.showToast('Updated');
});
}
}
When attempting to call the updateLicence method from within the modal component, I encounter the error "Cannot read properties of undefined (reading 'updateLicence')." However, calling it from a page works without issues, indicating that the LicencesService may not be registered when called from within the modal. Any suggestions on how to resolve this issue?