'header' 和 'buttons' 在 Ionic 4.1.1 中不存在于类型 'ToastOptions' 中,与文档相反
'header' and 'buttons' does not exist in type 'ToastOptions' in Ionic 4.1.1, contrary to documentation
我正在使用 Angular+Ionic 开发渐进式移动应用程序。
我想添加一些用户可以与之交互的吐司,所以我开始复制 their documentation. 中 ionic 提供的示例,而他们的示例是简单的“message-only”吐司,presentToast
, 对我来说工作正常,我无法复制他们的第二个例子,presentToastWithOptions
,没有得到错误说他们正在使用 non-existing 选项。
例子如下
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();
}
}
我得到的错误是
Object literal may only specify known properties, and 'header' does not exist in type 'ToastOptions'
和
Object literal may only specify known properties, and 'buttons' does not exist in type 'ToastOptions'
如果我忽略这些错误,代码仍会运行,但我没有得到按钮(出于我的目的,我并不真正关心 header)。我只能让一个按钮通过 showCloseButton
属性 出现,但我想让我的按钮做一些除了关闭 toast 之外的事情:/
以防万一,以下是有关我正在使用的离子版本的信息:
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
所以问题非常简单,我只是使用 npm update @ionic/angular
将@ionic/angular 从版本 4.1.1 更新到版本 4.11.10 :)
我正在使用 Angular+Ionic 开发渐进式移动应用程序。
我想添加一些用户可以与之交互的吐司,所以我开始复制 their documentation. 中 ionic 提供的示例,而他们的示例是简单的“message-only”吐司,presentToast
, 对我来说工作正常,我无法复制他们的第二个例子,presentToastWithOptions
,没有得到错误说他们正在使用 non-existing 选项。
例子如下
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();
}
}
我得到的错误是
Object literal may only specify known properties, and 'header' does not exist in type 'ToastOptions'
和
Object literal may only specify known properties, and 'buttons' does not exist in type 'ToastOptions'
如果我忽略这些错误,代码仍会运行,但我没有得到按钮(出于我的目的,我并不真正关心 header)。我只能让一个按钮通过 showCloseButton
属性 出现,但我想让我的按钮做一些除了关闭 toast 之外的事情:/
以防万一,以下是有关我正在使用的离子版本的信息:
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
所以问题非常简单,我只是使用 npm update @ionic/angular
将@ionic/angular 从版本 4.1.1 更新到版本 4.11.10 :)