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

后端 未结 9 815
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:55

    You did ask about using the simple toast call. Would you mind trying a custom toast show like the demo and add classes to the template?

    JS

    $mdToast.show(
      controller: 'ToastCtrl',
      templateUrl: 'views/shared/toast.html',
      hideDelay: 6000,
      position: $scope.getToastPosition()
    )
    

    TEMPLATE

    
      Custom toast!
      
       Close
      
    
    

    CSS

    md-toast.flash {
      background-color: red;
      color: white;
    }
    

    CONTROLLER (COFFEE)

    'use strict'
    
    ###*
     # @ngdoc function
     # @name angularApp.controller:ToastCtrl
     # @description
     # # ToastCtrl
     # Controller of the angularApp
    ###
    angular.module('angularApp')
      .controller 'ToastCtrl', ($scope) ->
        $scope.closeToast = ()->
          $mdToast.hide()
    

提交回复
热议问题