Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duration set to 0 not work #67

Open
abchjsabc opened this issue Aug 9, 2016 · 1 comment
Open

Duration set to 0 not work #67

abchjsabc opened this issue Aug 9, 2016 · 1 comment

Comments

@abchjsabc
Copy link

abchjsabc commented Aug 9, 2016

In line 21
args.duration = args.duration ? args.duration : defaultDuration;
If duration is set to 0, args.duration equals defaultDuration and it violates the doc

duration - Optional. The duration (in milliseconds) of message. A duration of 0 will prevent messages from closing automatically.

tandibar added a commit to tandibar/angular-notify that referenced this issue Aug 16, 2016
If `args.duration` is zero it will be `false` in javascript world. So we need to check for undefined.
@jkjustjoshing
Copy link

jkjustjoshing commented Sep 14, 2016

Workaround - set duration to any non-empty string. Since 'string' > 0 === false, but 'string' is truthy, it will prevent the timeout code from being triggered.

This is by no means a good solution, but it's a workable temporary workaround.

If you want to take it one step further, you could patch this for your local project globally with the following interceptor (test before using! :) ):

angular.module('myApp').config(function ($provide) {
    $provide.decorator('notify', function ($delegate) {
      return function (args) {
        if (typeof args !== 'object') {
          return $delegate(args);
        }

        if (args.duration === 0) {
          // Workaround
          args.duration = 'never close';
        }

        return $delegate(args);
      }
    });
  });

This will prevent things like notify.closeAll() from working, so beware!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants