Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ProPotential opened this issue Mar 7, 2023 · 1 comment

Comments

@ProPotential
Copy link

ProPotential commented Mar 7, 2023

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


@damienbod
Copy link
Owner

Thanks, good idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants