Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ionic framework 爱奥尼亚2号';不要在第页关闭_Ionic Framework_Ionic2 - Fatal编程技术网

Ionic framework 爱奥尼亚2号';不要在第页关闭

Ionic framework 爱奥尼亚2号';不要在第页关闭,ionic-framework,ionic2,Ionic Framework,Ionic2,我用吐司,但如果我有2个以上的吐司同时打开,吐司不会关闭 let toast = this.toastCtrl.create({ message: 'İnternet bağlantınızda veya sunucuda sorun olabilir.', duration: 3000, position: 'bottom' }); toast.present(); 保留对您的祝酒词的引用,并在演讲前对其调用dismise()。此解决方案将避免一次演示多个

我用吐司,但如果我有2个以上的吐司同时打开,吐司不会关闭

let toast = this.toastCtrl.create({
      message: 'İnternet bağlantınızda veya sunucuda sorun olabilir.',
      duration: 3000,
      position: 'bottom'
});
toast.present();

保留对您的祝酒词的引用,并在演讲前对其调用
dismise()
。此解决方案将避免一次演示多个
Toast

我喜欢自己使用的解决方案是处理服务中的所有
Toast
交互。并将该服务注入到您需要的任何组件/页面/服务中

烤面包服务:

import { Injectable } from '@angular/core';
import { ToastController, Toast } from 'ionic-angular';

@Injectable()
export class ToastService{
    toast: Toast = null;

    constructor(private toastCtrl: ToastController){ }

    presentToast(text:string):void{
        let toastData = {
            message: text,
            duration: 3000,
            position: 'top'
        }

        this.showToast(toastData);
    }

    presentClosableToast(text:string):void{
        let toastData = {
            message: text,
            showCloseButton: true,
            closeButtonText: 'X',
            position: 'top' 
        };

        this.showToast(toastData);
    }

    private showToast(data:any):void{
        this.toast ? this.toast.dismiss() : false;
        this.toast = this.toastCtrl.create(data);
        this.toast.present();
    }
}

请出示你的整个.ts页面。我想你创造了不定式吐司。我在我的项目中同时用2+标签进行了测试,但他们实际上拒绝了。服务不应该用于UI交互。有关替代解决方案,请参阅。