angularjs: $timeout usage (inside of service) angularjs: $timeout usage (inside of service) angularjs angularjs

angularjs: $timeout usage (inside of service)


myApp.factory('noticesData', function($rootScope, $timeout){    var obj = {};    obj.add = function(type, text){        var nId = $rootScope.notices.length + 1;        $rootScope.notices.push({id: nId, type:type, text:text+nId});        $timeout(function(){            obj.close(nId);        },3000);    }    obj.close = function(nId){        angular.forEach($rootScope.notices, function(notice, key){            if(notice.id == nId){                $rootScope.notices.splice(key,1);            }        });    }    return obj; });


Heres how to do it

$timeout(function () {    // do something}, 50);