alexcrack / angular-ui-notification

Angular.js service providing simple notifications using Bootstrap 3 styles with css transitions for animating
MIT License
536 stars 169 forks source link

return Notification object #16

Closed enapupe closed 9 years ago

enapupe commented 9 years ago

I think would be nice if Notification could return a object with it's configuration, methods, etc..

I would like to kill a notification if a ajax request is done. To this date there's no way to do this.

The necessary modification (draft) is proposed at https://github.com/alexcrack/angular-ui-notification/compare/master...enapupe:returnNotification?expand=1

Do you think this improvement is possible?

An example of use would be:

var test = Notification("Refreshing.....");
SomeService.regenerateAPIKey().then(function(){
    Notification("API Key sucessfully regenerated.");
    test.then(function(notification){
        notification.kill(true);
    });
});
alexcrack commented 9 years ago

Now you can use replaceMessage option.

The example using this option:

Notification({message: "Refreshing...", delay: 0});
SomeService.regenerateAPIKey().then(function(){
    Notification.success({
        message: "API Key successfully regenerated.", 
        replaceMessage: true
    });
});

First message will be replaced by the success message when regenerateAPIKey() promise will be resolved.

enapupe commented 9 years ago

I don't know.. Since you don't have controll over which notification one you are replacing, I think it may replace the wrong message . What happens if another promise triggers in the mean time?

alexcrack commented 9 years ago

Ok. I got it. My approach kills all the currently shown messages and shows new message. But you suggest to provide possibility to kill one specific message. I'll implement this feature.

alexcrack commented 9 years ago

Now in v0.0.11 (379a07d89a26978a0f8be1a7d46872abf88eb1a5) you can use this functionality.

var test = Notification("Refreshing.....");
SomeService.regenerateAPIKey().then(function(){
    Notification("API Key sucessfully regenerated.");
    test.then(function(notification){
        notification.kill(true);
    });
});