Repository navigation
Description
Prerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already report this problem, without success.
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?
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
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
sean-perkins commentedon Apr 14, 2023
@Asac2142 thanks for reporting this issue!
In Ionic v7,
modal/popoveris 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
ModalControllerprovider variable to something other thanmodal:I will update the issue title to reflect logging an error in this scenario. Thanks!
[-]bug: Cannot open a modal within another modal using ModalController[/-][+]bug: Ionic does not log error when overlay class has modal/popover property[/+]Asac2142 commentedon Apr 14, 2023
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.
chore(angular): log error when attempting to use reserved prop with m…
chore(angular): log error when attempting to use reserved prop with m…
godenji commentedon Jun 12, 2023
Was any consideration given to renaming Ionic's injected property to something other than
modal?This breaks any uprade to v7 that relies on
modalproperty used withModalController. Since Ionic's internal uses ofmodal.fooare minimal compared to user code it would have been nice if Ionic had reserved a different word, say,modalCtrl:)ionitron-bot commentedon Jul 12, 2023
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.