【问题标题】:Why isn't my styling being applied to a custom toast class?为什么我的样式没有应用于自定义 toast 类?
【发布时间】:2023-04-02 23:00:02
【问题描述】:

我想在使用 ionic 2 单击 div 时创建自定义 Toast,我在 ts 文件上创建 toast 时添加了一个 cssClass,但不会应用 css。 这是我的代码:

notification.ts:

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

/**
 * Generated class for the NotificationPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-notification',
  templateUrl: 'notification.html',
})
export class NotificationPage {

  constructor(public navCtrl: NavController, public navParams: NavParams, public toastCtrl: ToastController) {
  }

  ToastNotification() {
    const toast = this.toastCtrl.create({
      message: 'User was added successfully',
      duration: 100000,
      position: 'top',
      dismissOnPageChange: true,
      cssClass:  "custom-toast"

    });

    toast.onDidDismiss(() => {
      console.log('Dismissed toast');
    });

    toast.present();
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad NotificationPage');
  }

}

scss

.custom-toast {
            background-color: red;
            text-align: left;
        }

请帮忙!

【问题讨论】:

    标签: css ionic-framework ionic2 styles toast


    【解决方案1】:

    将你的 toast 样式移动到 app.scss 中,它会起作用。

    示例:

    app.scss

    .my-toast {
      .toast-wrapper {
        background: blue;
      }
    }
    

    【讨论】:

    • 当我设置 background-color: red 时,内容上方的一个完整的 div 像这样用红色着色:hpics.li/eb42395
    • 你能告诉我如何在 toast 本身上注入和 html 标签吗?
    • 你想完成什么?
    • 我正在尝试在 toast 中添加其他文本和图像
    • 我不完全确定该怎么做,我想你可能不得不覆盖 toast 组件。我用谷歌搜索了它并找到了这个:1.stackoverflow.com/questions/39426051/… 2.forum.ionicframework.com/t/…希望这对你有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-13
    • 1970-01-01
    • 1970-01-01
    • 2013-05-06
    • 1970-01-01
    • 2020-10-04
    相关资源
    最近更新 更多