Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
180
rated 0 times [  186] [ 6]  / answers: 1 / hits: 15086  / 10 Years ago, fri, october 3, 2014, 12:00:00

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);

}]);



  • what is the issue .


More From » angularjs

 Answers
17

UPDATED



Just replace



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


with



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


Check Angular's doc


[#69252] Wednesday, October 1, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
byrondonavanc

Total Points: 675
Total Questions: 107
Total Answers: 105

Location: Peru
Member since Fri, Oct 14, 2022
2 Years ago
byrondonavanc questions
;