Toast refuses to close automatically
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
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.
Closing, was never able to reproduce.
@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:

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
Is there an error in the log?
@ajoslin no error in Chrome console.
Can you try using the duration option instead of your custom timeout?
@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.
});
});
};
I wish I could reproduce this! Could you create a plunkr or jsfiddle showing this not working?
@ajoslin I'll see if I can get to work on it later this afternoon. If not, I will get to it ASAP.
Here's a plunk that demonstrates the issue: http://plnkr.co/edit/Dx2sshROvObiui0Enfa1?p=preview
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.
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.
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.
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.
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.