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

后端 未结 9 982
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:41

    There is an easier way by specifying a theme:

    $mdToast.simple().content("some test").theme("success-toast")
    

    And in your CSS:

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

    You could incorporate your message type to dynamically select a theme.

    Update: As Charlie Ng pointed out, to avoid warnings regarding use of an unregistered custom theme register it in your module using the theme provider: $mdThemingProvider.theme("success-toast")

    Another update: There was a breaking change created on 2 Dec 2015 (v1.0.0+). You now need to specify:

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

提交回复
热议问题