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

后端 未结 9 799
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:51

    One more step to rlay3's answer.

    Angular Material at 0.7.1 added warning to unregistered themes. https://github.com/angular/material/blob/master/CHANGELOG.md#071--2015-01-30

    If theme is not registered, every time the toast shows up, you will be getting a warning message in console like, for example:

    attempted to use unregistered theme 'custom-toast'
    angular.js:12416 Attempted to use unregistered theme 'custom-toast'. 
    Register it with $mdThemingProvider.theme().
    

    To get rid of the warning, you will need to configure the theme 'custom-toast' in your angular app:

    angular.module('myApp', ['ngMaterial'])
    .config(function($mdThemingProvider) {
      $mdThemingProvider.theme('custom-toast')
    });
    

    and use it like:

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

    references: https://material.angularjs.org/latest/#/Theming/04_multiple_themes

提交回复
热议问题