material icon indicating copy to clipboard operation
material copied to clipboard

Toast refuses to close automatically

Open nikhildev opened this issue 12 years ago • 15 comments

Hi,

I've made a service and a function in it to show toasts like this

myService.showToast = function(toastMessage, duration) { var toast = $materialToast({ template: 'I include my material-toast template here', duration: duration }); }

I then use the service as below

myService.showToast( 'Ooops, this is the toast message', duration);

Despite specifying the duration, the toast refuses to auto close. Ive tried changing to duration to 5000 and 0 with no luck. Am I doing something wrong?

Thanks

nikhildev avatar Sep 05 '14 07:09 nikhildev

Could you try this on the latest version of angular-material?

bower install angular-material#master - this will always install the latest-just-pushed-to-master version of material.

ajoslin avatar Sep 08 '14 12:09 ajoslin

Closing, was never able to reproduce.

ajoslin avatar Sep 12 '14 15:09 ajoslin

@ajoslin When I pulled from master I had the same issue as OP.

Using bower install angular-material and bower install angular-material#master gives me the issue.

My bower list: screen shot 2014-09-12 at 11 39 31 am

A piece of my controller:

$scope.login = function() {
    var loginData = {
      username: $scope.username,
      password: $scope.password
    };
    Userservice.login(loginData).success(function (loginResp) {
      $materialToast({
        template: '<material-toast>'+loginResp.message+'</material-toast>',
        position: 'bottom left',
        duration: 700
      });
    }).error(function (error) {
      $materialToast({
        template: '<material-toast>'+error.message+'</material-toast>',
        position: 'bottom left',
        duration: 2000
      });
    });
  };

The login message appears and stays.

The way I got the duration to work was kind of hacky. I created a controller for the toast and passed some locals:

My login controller:

$scope.login = function() {
    var loginData = {
      username: $scope.username,
      password: $scope.password
    };
    Userservice.login(loginData).success(function (loginResp) {
      $materialToast({
        controller: 'ToastCtrl',
        templateUrl: 'components/toast/toast.html',
        position: 'bottom left',
        locals: {
          closeTime: 700,
          message: loginResp.message
       }
      });
    }).error(function (error) {
      $materialToast({
        controller: 'ToastCtrl',
        templateUrl: 'components/toast/toast.html',
        position: 'bottom left',
        locals: {
          closeTime: 2000,
          message: error.message
       }
      });
    });
  };

My toast controller:

angular.module('myApp').controller('ToastCtrl', ['$scope', '$timeout', '$hideToast', 'closeTime', 'message', function ($scope, $timeout, $hideToast, closeTime, message) {
  $scope.message = message;
  $timeout(function () {
    $hideToast();
  }, closeTime);
}]);

The toast template file:

<material-toast>
  {{message}}
</material-toast>

Requesting a reopen from @ajoslin or @nikhildev

sparkyfen avatar Sep 12 '14 18:09 sparkyfen

Is there an error in the log?

ajoslin avatar Sep 12 '14 19:09 ajoslin

@ajoslin no error in Chrome console.

sparkyfen avatar Sep 12 '14 19:09 sparkyfen

Can you try using the duration option instead of your custom timeout?

ajoslin avatar Sep 12 '14 19:09 ajoslin

@ajoslin Yeah I have, see above, I have the non-hacky method which doesnt work as expected and then the missing duration with the hacky method works. Here is the non-hacky, expected way to do my toasts and they are stuck open as seen above:

$scope.login = function() {
    var loginData = {
      username: $scope.username,
      password: $scope.password
    };
    Userservice.login(loginData).success(function (loginResp) {
      $materialToast({
        template: '<material-toast>'+loginResp.message+'</material-toast>',
        position: 'bottom left',
        duration: 700 // Duration here.
      });
    }).error(function (error) {
      $materialToast({
        template: '<material-toast>'+error.message+'</material-toast>',
        position: 'bottom left',
        duration: 2000 // Duration here.
      });
    });
  };

sparkyfen avatar Sep 12 '14 19:09 sparkyfen

I wish I could reproduce this! Could you create a plunkr or jsfiddle showing this not working?

ajoslin avatar Sep 12 '14 19:09 ajoslin

@ajoslin I'll see if I can get to work on it later this afternoon. If not, I will get to it ASAP.

sparkyfen avatar Sep 12 '14 21:09 sparkyfen

Here's a plunk that demonstrates the issue: http://plnkr.co/edit/Dx2sshROvObiui0Enfa1?p=preview

wilsonjackson avatar Sep 13 '14 00:09 wilsonjackson

Ah, this is caused by a breaking change in ngAnimate as of 1.3.0 rc0: https://github.com/angular/angular.js/commit/bf0f5502b1bbfddc5cdd2f138efd9188b8c652a9

You'll need to switch from using the callback form to the promise form.

wilsonjackson avatar Sep 13 '14 04:09 wilsonjackson

I took a quick crack at fixing this, and the ngAnimate change is simple enough, but upgrading to rc1 breaks some stuff in angular-animate-sequence, which I don't have the time to troubleshoot at the moment.

wilsonjackson avatar Sep 13 '14 05:09 wilsonjackson

I found the same issue when I upgrade angular to rc.1 and angular-material to master... Duration option seems not working. And no error in the console of Chrome.

scarletsky avatar Sep 14 '14 10:09 scarletsky

At first, when I tested in plunkr with an older angular version, it worked. But look like the problem is with rc.1. This happened immediately after updating angular.

nikhildev avatar Sep 14 '14 11:09 nikhildev

OK, we'll force material to use rc1 and remove ngAnimate sequence for now. A new version of the sequencer is coming, but we don't use the current version of it right now.

thanks for the research.

ajoslin avatar Sep 14 '14 13:09 ajoslin