user3636439
user3636439

Reputation: 103

$timeout not working in angular.js

i am using $timeout in my controller but its not working!

app.controller("Friendsrequests",['$http','$log','$location','$timeout','$scope', function($http,$log,$location,$timeout,$scope){
//getting base url of application
this.baseUrl = function() {
        var base_url = window.location.origin;

        var pathArray = window.location.pathname;
        return base_url;
    //  return base_url+pathArray;
                };
// assigning to a variablebase_url('login/f_request');
var ThroughUrl = this.baseUrl()+'/keon/login/f_request';


//declare a variable
var ata = this;
ata.notifications = [ ] ;
ata.counts=' ';
//sending ajax request
 function getNotifications()
{
$http({method: 'POST', url: ThroughUrl,})
.success(function(data) {
    // this callback will be called asynchronously
    // when the response is available

//assign data to the variable
ata.notifications=data;
ata.counts =data.length;

  }).
  error(function(data, status, headers, config) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
  });

}

$timeout(function() {
    getNotifications();
}, 1000);

}]);

Upvotes: 0

Views: 15312

Answers (2)

Badri Chorapalli
Badri Chorapalli

Reputation: 99

while calling timeout in angularJS just remove Parentheses or brackets ()

$timeout(getNotifications, 1000);

getNotifications function will call after 1000 milliseconds(One second)

Upvotes: 1

Jevgeni
Jevgeni

Reputation: 2574

UPDATED

Just replace

$timeout(function() {
    getNotifications();
}, 1000);

with

$interval(function() {
   getNotifications();
},1000);

Check Angular's doc

Upvotes: 10

Related Questions