AspNetCoreOpeniddict icon indicating copy to clipboard operation
AspNetCoreOpeniddict copied to clipboard

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

Open ProPotential opened this issue 1 year ago • 1 comments

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']);
                }
            });


ProPotential avatar Mar 07 '23 03:03 ProPotential

Thanks, good idea

damienbod avatar Mar 07 '23 22:03 damienbod