I am dealing with an Angular 8 application that has a parent-child route relationship for creating new items. However, I have encountered an issue where the id of the parent component is initially set when the page loads to create a new item, but becomes null on subsequent ngOninit calls.
Here's the route relationship:
{
path: ':dossierId',
component: ViewComponent, children: [
{ path: 'item/new/:dossierItemType', component: ItemComponent}
],
resolve: {
dossier: DossierResolver,
dossierItems: DossierItemsResolver
}
},
and here is the item.component.ts file:
export class ItemComponent implements OnInit {
// Component properties and methods here
}
When examining the ID:
I see the following ID:
06637e72-8915-4735-9400-4ef7705194ea
However, upon debugging in Google Chrome, the ID turns null during ngOninit.
The URL is as follows:
http://localhost:4200/en/dossier/06637e72-8915-4735-9400-4ef7705194ea/item/new/Interview
An error message pops up:
core.js:6406 ERROR TypeError: Cannot set property 'id' of undefined
at SafeSubscriber._next (item.component.ts:58)
...
Subsequently, more errors follow:
...
Upon further examination of the params:
this.dossier.id = params.dossierId;
dossierItemType: "Interview"
This leads to issues with the save method:
Save Method Code Here
Now, this leads to an undefined value:
Error Message:
core.js:6406 ERROR Error: Required parameter dossierId was null or undefined when calling newDossierItem.
...
This error is related to an item being connected to a dossierId.