Search code examples
angularjsangular-toastr

angular-toastr preventOpenDuplicates is not working


I am using angular-toastr and trying to prevent duplicate toastr by using toastr option preventOpenDuplicates, but might be its not working or may be I am doing something wrong.

plunkr to reproduce issue

toastr :

toastr.error('test', 'open duplicate', {
  closeButton: true,
  tmeOut: 0,
  preventOpenDuplicates:true,
  progressBar: true
});

Solution

  • The way you tell angular-toastr to not show duplicate is by setting preventDuplicates to true inside the toastrConfig object. And not in the toastr.error or success or any opener for that matter.

    So, your code would look something like this:

    app.controller('MainCtrl', function($scope, toastr, toastrConfig) {
    
      toastrConfig.preventDuplicates = true;
      toastrConfig.preventOpenDuplicates = true;
      toastrConfig.progressBar = true;
      toastrConfig.closeButton = true;
      
      $scope.OpenToastr = function() {
        toastr.error('test', 'open duplicate');
      }
    });
    

    EDIT: Found it! It's the version! :)

    According to angular-toastr > CHANGELOG,

    Version 1.4.0

    • With preventOpenDuplicates you can prevent duplicates of opened toasts.

    The functionality got introduced in 1.4.0 and you were using 1.3.1.

    working plunker (updated)