how can I change the color of Toast depends on message type in Angular material $mdToast?

后端 未结 9 966
Happy的楠姐
Happy的楠姐 2021-02-03 17:10

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 typ

9条回答
  •  名媛妹妹
    2021-02-03 17:46

    register themes:

    $mdThemingProvider.theme("success-toast");
    $mdThemingProvider.theme("error-toast");
    

    add css:

    md-toast.md-error-toast-theme div.md-toast-content{
        color: white !important;
        background-color: red !important;
    }
    
    md-toast.md-success-toast-theme div.md-toast-content{
        color: white !important;
        background-color: green !important;
    }
    

    use:

    $mdToast.show(
        $mdToast.simple()
            .content(message)
            .hideDelay(2000)
            .position('bottom right')
            .theme(type + "-toast")
    );
    

提交回复
热议问题