phillipsnick / nickphillips.co

Source for nickphillips.co
MIT License
0 stars 0 forks source link

AngularJS - Alert timeouts #66

Closed phillipsnick closed 9 years ago

phillipsnick commented 9 years ago

Some potential working code copied from a website earlier

 return alertService = {
    add: function(type, msg, timeout) {
        $rootScope.alerts.push({
            type: type,
            msg: msg,
            close: function() {
                return alertService.closeAlert(this);
            }
        });

        if (timeout) {
            $timeout(function(){
                alertService.closeAlert(this);
            }, timeout);
        }
    },
    closeAlert: function(alert) {
        return this.closeAlertIdx($rootScope.alerts.indexOf(alert));
    },
    closeAlertIdx: function(index) {
        return $rootScope.alerts.splice(index, 1);
    }

};
phillipsnick commented 9 years ago

Testing timeouts... http://stackoverflow.com/questions/17418716/unit-testing-angular-service-that-uses-timeout-with-jasmines-mock-clock