I am trying to use View Hooks on a modal, but I am facing an error: modal.willLeave.subscribe
does not exist.
Here is the full code of the file:
import { IonicPage, ModalController, NavController, NavParams } from 'ionic-angular';
import { Component } from '@angular/core';
import { Quote } from '../../data/quote.interface';
import { QuotePage } from '../quote/quote';
import { QuotesProvider } from '../../providers/quotes/quotes';
@IonicPage()
@Component({
selector: 'page-favorites',
templateUrl: 'favorites.html',
})
export class FavoritesPage {
quotes: Quote[];
constructor(public navCtrl: NavController, public navParams: NavParams, public quotesService: QuotesProvider, public modalCtrl: ModalController) {
}
ionViewWillEnter() {
this.quotes = this.quotesService.getFavoriteQuotes();
}
onViewQuote(quote: Quote) {
const modal = this.modalCtrl.create(QuotePage, quote);
modal.present();
modal.onDidDismiss((remove: boolean) => {
console.log(remove);
});
modal.willLeave.subscribe((remove: boolean) => {
console.log(remove);
});
}
}
The other file I am passing the data from modal using View Controller:
import { IonicPage, NavController, NavParams, ViewController } from 'ionic-angular';
import { Component } from '@angular/core';
@IonicPage()
@Component({
selector: 'page-quote',
templateUrl: 'quote.html',
})
export class QuotePage {
person: string;
text: string;
constructor(public navCtrl: NavController, public navParams: NavParams, public viewCtrl: ViewController) {
}
ionViewDidLoad() {
this.person = this.navParams.get('person');
this.text = this.navParams.get('text');
}
onClose(remove = false) {
this.viewCtrl.dismiss(remove);
}
}
What am I doing wrong?