如何根据 Angular 材料 $mdToast 中的消息类型更改 Toast 的颜色? [英] how can I change the color of Toast depends on message type in Angular material $mdToast?

查看:34
本文介绍了如何根据 Angular 材料 $mdToast 中的消息类型更改 Toast 的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 $mdToast.simple().content("some test") 时,它以黑色显示吐司.如何将该颜色更改为红色、黄色等,取决于错误消息的类型,例如错误、警告和成功.

While using $mdToast.simple().content("some test") it is showing the toast with black color. how can I change that color to red, yellow and so, depends on the type of the error messages like error, warning and success.

this类似的问题.

推荐答案


为了正确的实现,请使用 rlay3s 解决方案如下:)!

过时:
我在使用 jhblacklocks 解决方案显示自定义文本时遇到了问题,所以我决定使用模板"这样做:

OUTDATED:
I had problems displaying custom text with jhblacklocks solution, so I decided to do it like this using 'template':

var displayToast = function(type, msg) {

    $mdToast.show({
        template: '<md-toast class="md-toast ' + type +'">' + msg + '</md-toast>',
        hideDelay: 6000,
        position: 'bottom right'
    });
};

我还在我的 .css 文件中添加了不同的类型:

I also added the different types in my .css file:

.md-toast.error {
    background-color: red;
}

.md-toast.success {
    background-color: green;
}

不知道这是不是最漂亮的方法,但我不需要每个对话框类型的模板文件,显示自定义文本真的很容易.

Don't know if this is the most beautiful approach, but I don't need a template files for each dialog type and displaying custom text is really easy.

这篇关于如何根据 Angular 材料 $mdToast 中的消息类型更改 Toast 的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆