Overlays in 2.0.0-beta.11
See original GitHub issueShort description of the problem:
After upgrading to beta.11 (which I had to do because it finally brings support for @angular/forms) and applying the code changes suggested in the upgrade guide (use AlertController.create
, and alert.present
rather than NavController.present
) my app is broken. I think this is because of the decision to make overlays global (app-wide) rather than constrained by the containing NavController.
Running the following code in my app results in an error (the same code used to work in beta.10 using nav.present):
const alert = this.alertController.create({/*some options*/);
alert.present().
The above code results in the following error:
TypeError: Cannot read property 'insertViews' of undefined
at App.present (eval at <anonymous> (main.bundle.js:1), <anonymous>:171:28)
at Alert.present (eval at <anonymous> (main.bundle.js:1), <anonymous>:98:26)
at DialogExplorerComponent.addNode (eval at 1473 (1.chunk.js:1), <anonymous>:138:16)
Stepping through the code in the debug console reveals that the _portal
field of that App instance is undefined:
image
Is there some way of using the beta.11 API to achieve the same behavior as beta.10, that is, having overlays be constrained by their containing NavController rather than app-wide as in beta 11?
What behavior are you expecting?
That I’d be able to use overlays like Alert, Toast as I could in beta.10.
Which Ionic Version? 1.x or 2.x 2.0.0-beta.11
Issue Analytics
- State:
- Created 7 years ago
- Comments:25 (10 by maintainers)
Not sure if this is due to the same root cause, but for me I’ve found DI has broken for my popups. Upgraded to Beta 11 and changed how Popup’s get created to be via the PopupController with constructor injection. A vanilla popup works fine, but if the component that we’re passing into the popup relies on a custom service that we put in the root component’s providers, it can’t seem to find it where previously it did. So just end up getting a “No provider for XXXX”.
@szerner @TheMadBug I’m wondering if issue #7592 might not be the ultimate culprit here. Obviously there’s been a change in beta 11 affecting DI and I’m wondering if the injectors used on portals/overlays/navs etc in beta 11 are properly reusing their parent injectors. It could explain why we’re getting null reference errors (we could be getting a new instance of App instead of the preconfigured global instance resulting in an undefined _portal because setPortal was never called on that instance). Injector inheritance should follow the ng2 model and registering providers in ionicBootstrap alone is not a solution for that.