Issue
I am developing a progressive mobile application using Angular+Ionic.
I wanted to add a couple of toasts that the user could interact with, so I started out by copying the example ionic provides in their documentation. While their example of a simple "message-only" toast, presentToast
, works fine for me, I cannot replicate their second example, presentToastWithOptions
, without getting errors saying that they are using non-existing options.
The example is as follows
import { Component } from '@angular/core';
import { ToastController } from '@ionic/angular';
@Component({
selector: 'toast-example',
templateUrl: 'toast-example.html',
styleUrls: ['./toast-example.css'],
})
export class ToastExample {
async presentToastWithOptions() {
const toast = await this.toastController.create({
header: 'Toast header',
message: 'Click to Close',
position: 'top',
buttons: [
{
side: 'start',
icon: 'star',
text: 'Favorite',
handler: () => {
console.log('Favorite clicked');
}
}, {
text: 'Done',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
}
]
});
toast.present();
}
}
The errors I get are
Object literal may only specify known properties, and 'header' does not exist in type 'ToastOptions'
and
Object literal may only specify known properties, and 'buttons' does not exist in type 'ToastOptions'
The code still runs if I ignore these errors, but I don't get buttons (I don't really care about the header for my purposes). I can only get a button to appear through the showCloseButton
property, but I wanted to have my button do something other than close the toast :/
Just in case, here's the info about the ionic version I'm working with:
Ionic:
Ionic CLI : 5.4.16
Ionic Framework : @ionic/angular 4.1.1
@angular-devkit/build-angular : 0.13.9
@angular-devkit/schematics : 7.2.4
@angular/cli : 7.3.10
@ionic/angular-toolkit : 1.5.1
Solution
So the problem was super simple, I just updated @ionic/angular from version 4.1.1 to version 4.11.10 using npm update @ionic/angular
:)
Answered By - Luis Sosa
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.