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

后端 未结 9 802
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:44

    Just to give another option, $mdToast allows to define toast presets that you can easily instantiate in this way, though i'm struggling to understand how to change the text content, any idea?

    $mdToast.show(
      $mdToast.error()
    );
    

    The presets are defined as explained on https://material.angularjs.org/latest/api/service/$mdToast :

    $mdToastProvider.addPreset('error', {
      options: function() {
        return {
          template:
            '' +
              '
    ' + '
    ' + '
    ', position: 'top left', hideDelay: 2000, toastClass: 'toast-error', controllerAs: 'toast', bindToController: true }; } });

提交回复
热议问题