Skip to content
This repository was archived by the owner on May 4, 2022. It is now read-only.
This repository was archived by the owner on May 4, 2022. It is now read-only.

ViewController no longer has dismiss method #678

@ionitron-bot

Description

@ionitron-bot

Original issue by @russcarver on 2018-09-05T18:50:39Z

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions