question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ViewController no longer has dismiss method

See original GitHub issue

Bug Report

Ionic Info Run ionic info from a terminal/cmd prompt and paste the output below.

   ionic (Ionic CLI)          : 4.1.1
   Ionic Framework            : @ionic/angular 4.0.0-beta.5
   @angular-devkit/core       : 0.7.5
   @angular-devkit/schematics : 0.7.5
   @angular/cli               : 6.1.5
   @ionic/ng-toolkit          : 1.0.7
   @ionic/schematics-angular  : 1.0.5

Cordova:

   cordova (Cordova CLI) : 7.1.0
   Cordova Platforms     : none
   Cordova Plugins       : no whitelisted plugins (0 plugins total)

System:

   Android SDK Tools : 26.1.1 (/Users/rc101077/Library/Android/sdk)
   ios-deploy        : 2.0.0
   ios-sim           : 7.0.0
   NodeJS            : v8.11.3 (/Users/rc101077/.nvm/versions/node/v8.11.3/bin/node)
   npm               : 6.2.0
   OS                : macOS High Sierra
   Xcode             : Xcode 9.4.1 Build version 9F2000

Describe the Bug Trying to close a Modal in the same way as Ionic3. The dismiss method on the ViewController no longer exists.

Steps to Reproduce Steps to reproduce the behavior:

  1. Create a modal with ModalController
  2. Grab the ViewController in your component’s constructer
  3. Call this.viewCtrl.dismiss
  4. On compile, the error shows that dismiss is not part of ViewController

Related Code

  public async openReset(): Promise<void> {
    const resetModal: HTMLIonModalElement = await this.modalController.create({
      backdropDismiss: false,
      component: ResetModalPage,
      componentProps: {
        foo: 'foo',
        bar: 2
      }
    });
    return await resetModal.present();
  }

The modal presents fine. Inside the ResetModalPage:

  public constructor(private navParams: NavParams, private viewCtrl: ViewController) {
    this.foo = this.navParams.data.foo;
    this.bar = this.navParams.data.bar;
  }

  public cancel(): void {
    this.viewCtrl.dismiss(); // Error is here
  }

Expected Behavior In Ionic3, this worked find and you could even pass data in the dismiss which you could receive on the “outside” with onDidDismiss.

Workaround For now, I’m passing in the modal to the constructed component and calling it’s dismiss method:

  componentProps: {
    getModal: (): HTMLIonModalElement => { return resetModal; },
    foo: 'foo',
    bar: 2
  }

  public cancel(): void {
    this.getModal().dismiss();
  }

but this seems hacky at best. I also tried calling dismiss directly on the ModalController and trying goBack() on the NavController, but neither worked.

I also noted that ViewController no longer comes from @ionic/angular but now @ionic/angular/dist/types/components/nav/view-controller

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
doendercommented, Sep 6, 2018

@russcarver Did you try calling this.modalCtrl.dismiss() within the modal component itself (instead of the component where you launched the modal) ?

0reactions
ionitron-bot[bot]commented, Nov 29, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

dismiss(animated:completion:) - Apple Developer
The block to execute after the view controller is dismissed. This block has no return value and takes no parameters. You may specify...
Read more >
ViewController no longer has dismiss method #15479 - GitHub
Trying to close a Modal in the same way as Ionic3. The dismiss method on the ViewController no longer exists. Steps to reproduce...
Read more >
Swift View Controller won't dismiss - Stack Overflow
I tried various ways to dismiss the view but none worked. I am new to swift and really need help. Let me know...
Read more >
iOS Lifecycle When Dismissing a Modal View With ...
Since iOS 13, you have been able to implement a half-modal behavior as a screen transition by default and close the modal view...
Read more >
Best way to dismiss Keyboard in a View Controller iOS (Swift)
UITextFields has keyboard as first responders, as soon you begin editing keyboard shows up. It is developer's responsibility to write code to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found