Skip to content

bug: Ionic does not log error when overlay class has modal/popover property #27205

Closed

Description

@Asac2142

Prerequisites

Ionic Framework Version

v7.x

Current Behavior

I am working on an Angular project, version 15, I am using standalone components, and inject function for dependency injection.

I have a parent component, a first component, and second component. both first and second are modals

The definition of these components are as follows:

import { IonicModule, ModalController } from '@ionic/angular';
...
 // PARENT COMPONENT
@Component({
   selector: 'parent',
   standalone: true, 
   template: `<button (click)="onClick()">Open first</button>`,
   imports: [CommonModule, IonicModule]
})
export class ParentComponent {
  private _modal = inject(ModalController)

  async onClick() {
    const modal = await this._modal.create({ component: FirstComponent });
    await modal.present() // it works here
  }
}

// FIRST COMPONENT
@Component({
   selector: 'first',
   standalone: true, 
   template: `
     <button (click)="onClick()">Open 2nd</button>
     <button (click)="onSave()">Save</button>
     <button (click)="onCancel()">Cancel</button>
  `,
   imports: [CommonModule, IonicModule]
})
export class FirstComponent {
    private _m = inject(ModalController);

    onSave() { this_m.dismiss() } // this works with no issues

    onCancel() { this._m.dismiss() } // this works with no issues

    async onClick(): void {
      const modal = await this._m.create({ component: SecondComponent });
     await modal.present() // errors here
    }
}

// SECOND COMPONENT
@Component({
   selector: 'second',
   standalone: true, 
   template: `<p>Second!</p>`,
   imports: [CommonModule, IonicModule]
})
export class FirstComponent {
   private m = inject(ModalController);
}  

While presenting the first component, and opening the second component, I get the following error, where create-transaction component is the first component. What am I missing here? Is it possible to open a modal within another one?
When triggering modal.dismiss in the first component, it works, why it doesn't when opening another one?

image

Expected Behavior

It should allow to open a modal from another modal using the ModalController

Steps to Reproduce

npm install
ionic serve

press the fab-button and click button Category, watch the error on console

Code Reproduction URL

https://github.com/Asac2142/expenses

Ionic Info

[WARN] Error loading @capacitor/ios package.json: Error: Cannot find module '@capacitor/ios/package.json'
       
       Require stack:
       - /usr/local/lib/node_modules/@ionic/cli/lib/project/index.js
       - /usr/local/lib/node_modules/@ionic/cli/lib/index.js
       - /usr/local/lib/node_modules/@ionic/cli/index.js
       - /usr/local/lib/node_modules/@ionic/cli/bin/ionic

Ionic:

   Ionic CLI                     : 7.0.1 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 7.0.1
   @angular-devkit/build-angular : 15.2.5
   @angular-devkit/schematics    : 15.2.5
   @angular/cli                  : 15.2.5
   @ionic/angular-toolkit        : 9.0.0

Capacitor:

   Capacitor CLI      : 4.7.3
   @capacitor/android : 4.7.3
   @capacitor/core    : 4.7.3
   @capacitor/ios     : not installed

Utility:

   cordova-res : not installed globally
   native-run  : 1.7.2

System:

   NodeJS : v18.13.0 (/usr/local/bin/node)
   npm    : 9.6.3
   OS     : Linux 5.15

Additional Information

"dependencies": {
    "@angular/common": "^15.0.0",
    "@angular/core": "^15.0.0",
    "@angular/forms": "^15.0.0",
    "@angular/platform-browser": "^15.0.0",
    "@angular/platform-browser-dynamic": "^15.0.0",
    "@angular/router": "^15.0.0",
    "@capacitor/android": "4.7.3",
    "@capacitor/app": "4.1.1",
    "@capacitor/core": "4.7.3",
    "@capacitor/haptics": "4.1.0",
    "@capacitor/keyboard": "4.1.1",
    "@capacitor/status-bar": "4.1.1",
    "@ionic/angular": "^7.0.0",
    "@ionic/storage-angular": "^3.0.6",
    "@ngrx/effects": "^15.4.0",
    "@ngrx/entity": "^15.4.0",
    "@ngrx/store": "^15.4.0",
    "@ngrx/store-devtools": "^15.4.0",
    "date-fns": "^2.29.3",
    "ionicons": "^7.0.0",
    "rxjs": "~7.5.0",
    "tslib": "^2.3.0",
    "uuid": "^9.0.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^15.0.0",
    "@angular-eslint/builder": "^15.0.0",
    "@angular-eslint/eslint-plugin": "^15.0.0",
    "@angular-eslint/eslint-plugin-template": "^15.0.0",
    "@angular-eslint/schematics": "^15.0.0",
    "@angular-eslint/template-parser": "^15.0.0",
    "@angular/cli": "^15.0.0",
    "@angular/compiler": "^15.0.0",
    "@angular/compiler-cli": "^15.0.0",
    "@angular/language-service": "^15.0.0",
    "@capacitor/cli": "4.7.3",
    "@ionic/angular-toolkit": "^9.0.0",
    "@types/jasmine": "~4.0.0",
    "@types/node": "^12.11.1",
    "@types/uuid": "^9.0.1",
    "@typescript-eslint/eslint-plugin": "5.3.0",
    "@typescript-eslint/parser": "5.3.0",
    "eslint": "^7.6.0",
    "eslint-plugin-import": "2.22.1",
    "eslint-plugin-jsdoc": "30.7.6",
    "eslint-plugin-prefer-arrow": "1.2.2",
    "jasmine-core": "~4.3.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.0.0",
    "prettier": "2.8.7",
    "ts-node": "~8.3.0",
    "typescript": "~4.8.4"
  },

Activity

  1. self-assigned this
    on Apr 14, 2023
  2. sean-perkins commented on Apr 14, 2023

    @sean-perkins
    Contributor

    @Asac2142 thanks for reporting this issue!

    In Ionic v7, modal/popover is a reserved member that Ionic will assign directly to the class of the presented overlay. Admittedly, we should check if the class already has a member assigned to that name and log an error.

    To work around this issue/the recommended path for implementation is to rename your ModalController provider variable to something other than modal:

    private modalCtrl: ModalController = inject(ModalController);

    I will update the issue title to reflect logging an error in this scenario. Thanks!

  3. changed the title [-]bug: Cannot open a modal within another modal using ModalController[/-] [+]bug: Ionic does not log error when overlay class has modal/popover property[/+] on Apr 14, 2023
  4. added
    package: angular
    on Apr 14, 2023
  5. added
    type: bug
    on Apr 14, 2023
  6. removed their assignment
    on Apr 14, 2023
  7. Asac2142 commented on Apr 14, 2023

    @Asac2142
    Author

    Thank you @sean-perkins for your reply. I didn't know about the reserved modal name...
    I used your workaround and it works, thank you very much.

  8. added a commit that references this issue on May 18, 2023
    07f013c
  9. added a commit that references this issue on May 22, 2023
    138094d
  10. godenji commented on Jun 12, 2023

    @godenji

    Was any consideration given to renaming Ionic's injected property to something other than modal?

    This breaks any uprade to v7 that relies on modal property used with ModalController. Since Ionic's internal uses of modal.foo are minimal compared to user code it would have been nice if Ionic had reserved a different word, say, modalCtrl :)

  11. ionitron-bot commented on Jul 12, 2023

    @ionitron-bot

    Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

  12. locked and limited conversation to collaborators on Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: angulartype: bug

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions