Error: The Ionic Angular modal is being dismissed along with the entire page due to a Maximum call stack size exceeded RangeError

My challenge is to add new users to my app using a modal registration process. However, I encounter an issue when attempting to make two calls in the component: 1- registering on Firebase and 2- registering on DB. Due to this, the modal closes abruptly, and the page reverts to the previous one, prompting an error in the log.

Seeking assistance to resolve this issue.

register.page.html

<ion-content>
<ion-fab (click)="setOpen('isModalOpen', true)" vertical="bottom" horizontal="end" slot="fixed">
    <ion-fab-button id="user-modal">
      <ion-icon name="add"></ion-icon>
    </ion-fab-button>
  </ion-fab>

  <ion-modal trigger="user-modal">
    <ng-template>
    <ion-header>
        <ion-toolbar>
          <ion-buttons slot="start"gt;
            <ion-button (click)="cancel()">
              <ion-icon name="arrow-back-outline"></ion-icon>
            </ion-button>
          </ion-buttons>
          <ion-title>Create User</ion-title>
        </ion-toolbar>
      </ion-header>
        <ion-content>
            <ion-item class="new-user">
                <ion-label position="floating">Email:</ion-label>
                <ion-input type="email" [(ngModel)]="email"></ion-input>
            </ion-item>
            <ion-button (click)="sendUser()">Cadastrar</ion-button>
        </ion-content>
    </ng-template>
  </ion-modal>
</ion-content>

register.page.ts


@Component({
  selector: 'register-admin',
  templateUrl: './register-admin.page.html',
  styleUrls: ['./register-admin.page.scss'],
})
export class RegisterPage implements OnInit {

  @ViewChild(IonModal) modal: IonModal;

    constructor(private userService: UserService) {}

    sendUser() {
      this.userService.createUser(user)
        .then(() => {
            this.userService.createUserInfo(user)
                .then(() => {
                    alert('User created!');
                    this.modal.dismiss(null, 'cancel');
                });
          }).catch(err => {
           if (err.message.includes('already')) {
             alert('Already Created');
           } else if (err.message.includes('Password')) {
             alert('Password have to be more than 6 digits.');
           } else {
             alert('Try again Later');
           }
         });
      
}

user.service.ts

 createUser(user) {
    return this.fireAuth.createUserWithEmailAndPassword(user.email, user.pass)      
 }

 resetPassword(email: string) {
    return this.fireAuth.sendPasswordResetEmail(email);
 }

 createUserInfo(user: any) {
    return this.db.list('/user').push({
        name: user.name,
        email: user.email,
        admin: user.admin === 'true' ? true : false,
        type: user.type
    });
}

Upon invoking the function, I consistently encounter issues such as the modal closing prematurely or freezing the screen while displaying the following console error:

Uncaught RangeError: Maximum call stack size exceeded.
    at focusElement (helpers-eed79a2b.js:158:1)
    at focusFirstDescendant (overlays-4fbe89bd.js:4095:17)
    at trapShadowFocus (overlays-4fbe89bd.js:4235:7)
    at trapKeyboardFocus (overlays-4fbe89bd.js:4252:5)
    at HTMLDocument.<anonymous> (overlays-4fbe89bd.js:4261:41)
    at ZoneDelegate.invokeTask (zone.js:434:1)
    at Zone.runTask (zone.js:205:1)
    at ZoneTask.invokeTask [as invoke] (zone.js:516:1)
    at invokeTask (zone.js:1656:1)
    at HTMLDocument.globalZoneAwareCaptureCallback (zone.js:1725:1)

Note: The error may also originate from focusLastDescendant.

I examined the focus behavior of the modal but found no apparent issues causing the error upon closure. When testing with a single promise call, the functionality works without errors; hence, it points towards a specific interaction with the dual promises. It's unclear whether other project elements impact this component. I have a similar page with only one promise call that functions perfectly fine.

Answer №1

It turns out the issue arose when I was retrieving all users using snapshotChanges(), which was triggering a reevaluation of every change on that route. The initial call was made with an navCtrl forward, leading to this misunderstanding. Switching to valueChange() has resolved the problem.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to update a page and retrieve fresh data from a service in Angular?

On my webpage, there is a table and two charts coming from three different controllers. I am looking for a way to refresh all of them simultaneously by clicking on a single refresh button. This will allow the data to be fetched from the webservice again an ...

Dealing with challenges in integrating ngx-masonry with Angular 14

I am currently working with Angular 14 framework and the ngx-masonry library (https://www.npmjs.com/package/ngx-masonry/v/14.0.1). However, I am facing some issues where it is not functioning correctly. I would appreciate any assistance or guidance on how ...

How do I retrieve a template variable or reference from typescript in Angular?

Within my Angular project, I am attempting to retrieve the value from <td [innerHTML]='rupee.replaceHTML' #term></td> and assign it to the variable newdata. Exploring further into the functionality, there are 2 buttons named change a ...

Changes made to one order's information can impact the information of another order

Currently, I am in the process of developing a unique shopping cart feature where users input a number and a corresponding product is added to a display list. Users have the ability to adjust both the price and quantity of the products, with the total pric ...

Angular Material Design Components is displaying the error message "The mixin mdc-top-app-bar-fill-color does not exist"

Currently, I'm working with angularCLI and angular-MDC and I am trying to implement the second color from my styles.scss file. I came across this syntax on the following website which is mdc-top-app-bar-fill-color($color). When I tried using it, I re ...

angular2-jwt: AuthHttp triggers a 'Expected 0 type arguments, but received 1' error

When utilizing AuthHttp from the angular2-jwt library in the code snippet below, an error is encountered: "Expected 0 type arguments, but got 1." public fetchData(): Observable<User[]>{ const apiUrl = environment.apiUrl + "users"; return this.auth ...

Unable to access variables of nested components in Angular 2 templates

Recently delving into Angular2, I've encountered a simple issue. My aim is to create a basic parent component that acts as a container for dynamic boxes, each with its own properties and data. Here's what I've accomplished so far: The con ...

create an endless loop to animate in angular2

Is there a way to add iterations, or something similar to the ccs3 animation-iteration-count in Angular 2 animations? I've looked but can't find anything related. How can we apply an infinite play to the animation? Where should we include that o ...

Leveraging $sceDelegateProvider for allowing Youtube in Typescript

I'm currently facing an issue with my app where I am trying to enable users to input Youtube URLs for videos to be displayed on the site. However, before implementing this feature, I need to whitelist Youtube. How can I adjust my typescript file (app. ...

What is the appropriate Typescript return type to use for a $http request that only returns a successful response with no content?

I recently developed a Typescript service: class SettingsService implements ISettingsService { public info = {}; public backupInfo = {}; public userConfig = {}; public isLoaded = false; constructor( private $http: ng.IHttpSer ...

The Jasmine Angular PrimeNG test for WindowMaximizeIcon is encountering 16 failures

Currently in the process of upgrading my Angular application from version 15 to 16. Encountered an issue with my Jasmine test that involves PrimeNG's dialog. The error message is shown below: Chrome 114.0.0.0 (Windows 10) IncidentGridComponent should ...

The reason why Node struggles to resolve the absolute path to a directory post bundling the code using Webpack

Looking to create an AWS-CDK library using typescript and bundling it with Webpack. To include some static files from the Project root, the Copy-Plugin is used in the webpack config to move them to the dist folder. However, when referencing the imported ...

The factory class is responsible for generating objects without specifying their type

I manage a factory that specializes in facilitating dependency injection. Here's an example of what it looks like: import SomeImportantObject from "./SomeImportantObject" import DataInterface from "./DataInterface" class NoodleFactory { this.depen ...

How can Angular developers properly implement token refreshing in their applications?

Recently, I've been struggling with implementing a logic in my code. I have a specific requirement: Whenever there is a signed request (signed - means it has a JWT token for authenticated users) made to the API backend, the API backend may respond w ...

What is the best method to select pagination in a Spring Boot application?

I am seeking advice on implementing pagination for my table data in a Spring Boot application. The dataset is quite long, so I have implemented pagination to retrieve the data from the database efficiently. Currently, I have a REST method in my Spring Boo ...

Can we determine the type signature of useCallback for an event handler by inference?

Currently, I am working with TypeScript and React to implement a callback function using an arrow function on a Material UI <Select> component: import React from 'react'; import MenuItem from '@material-ui/core/MenuItem'; import ...

Disregard the message stating "error TS2683: 'this' implicitly assumes the type 'any' due to lack of type annotation."

Is there a solution for avoiding the TypeScript error when trying to create a shared utility function for dumping scattered objects in code without repeating the same code over and over? I have tried different approaches and it seems to work fine in Chrome ...

Unable to add elements to an array with a UnionType

I have been experimenting with UnionTypes in TypeScript and I had an idea for a scenario where they could be useful. However, I am puzzled by the error message that keeps popping up: Argument of type '{ name: string; }' is not assignable to par ...

Using an external HTML file to import a template into Vue.js single file components

I've been tackling a Vuejs project that involves using vue-property-decorator in single file components. I'm trying to figure out how to import the template from an external HTML (or different) file, but so far I haven't found a solution. I& ...

Alert: Angular has detected that the entry point '@libray-package' includes deep imports into 'module/file'

Recently updated the project to Angular 9.1 and now encountering multiple warnings from the CLI regarding various libraries, such as these: Warning: The entry point '@azure/msal-angular' includes deep imports into 'node_modules/msal/lib-com ...