[solved] .dismiss() button close Modal error

Hello, i have a problem with Close button modal. (click)=“fechar()”

(Modal File)

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, ViewController } from 'ionic-angular';

@IonicPage()
@Component({
  selector: 'conta',
  templateUrl: 'conta.html',
})
export class conta {
  loading: any;
  conta: any;
  descricao: any;
  constructor(public navCtrl: NavController, public navParams: NavParams, public ViewController: ViewController) {
      this.conta = this.navParams.get("parametro") || {descricao: "Spifa"};
  }
  fechar() {
    this.ViewController.dismiss();
  }
  salvar() {
    this.ViewController.dismiss(this.conta);
  }
  ionViewDidLeave() {
    this.ViewController.dismiss().catch(() => console.log('Some bug going on..'));
  }
}

(Modal HTML)


<!--
  Generated template for the Conta page.

  See http://ionicframework.com/docs/components/#navigation for more info on
  Ionic pages and navigation.
-->
<ion-header>

  <ion-toolbar>
    <ion-buttons start>
      <button ion-button navPop (click)="fechar()">
        <ion-icon [name]="'close'" ></ion-icon>
      </button>
    </ion-buttons>
      <ion-title>Cadastro</ion-title>
    </ion-toolbar>

</ion-header>


<ion-content padding>
    <ion-list>
      <ion-item>
        <ion-label Stacked>Descrição</ion-label>
        <ion-input type="text" [(ngModel)]="conta.descricao"></ion-input>
      </ion-item>
    </ion-list>
   <button ion-button full (click)="salvar()">Salvar</button>
</ion-content>

error

I’m guessing that’s due to the fact you’re putting the ViewController in your Constructor with a capital V. Change it to public viewCtrl: ViewController

and your fechar Function to viewCtrl as well. What is dat navPop doing on your button? I don’t think thats necessary: <button ion-button navPop (click)="fechar()">

1 Like

the problem is navPop, i remove this from html and work correct. thank you help.