Skip to content

Error in HTML [(ngModel)]="DataEventRecord.name" null after dataeventrecords-createΒ #52

@ProPotential

Description

@ProPotential

Hi Damien,
First, Thank you! This is a fantastic repo! You and Kevin Chalet have done some really amazing work.

I get an error in the console of the AngularCliCodeFlowPkce project after creating a new dataevent record in the dataeventrecords-create.component.html: Cannot read properties of null (reading 'name')

The call to the dataEventRecordsService.Add() in the component does not return a value, so on line 45 the .subscribe((data: any) => this.DataEventRecord = data, will set this.DataEventRecord to null, and if the model updates before it can navigate it will throw the error and prevent this._router.navigate() from doing it's thing.

So, just commenting out line 45 takes care of it. But also, since Rxjs Subscription is deprecated, It might be better to use the .subscribe({ next: (), error: (), complete: ()}); pattern something like this:

 
           this._dataEventRecordsService.Add(this.DataEventRecord).subscribe({ 
                next: (data: any) => {
                    console.log("Data", data);
                   //this.DataEventRecord = data;
                },
               error: err => {console.log("ERROR contacting api", err);},
               complete: () => {
                   console.log("Successfully added DataEventRecord");
                   this._router.navigate(['/dataeventrecords']);
                }
            });


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions