gpt4 book ai didi

javascript - $timeout 在 angular.js 中不起作用

转载 作者:行者123 更新时间:2023-11-28 11:12:09 24 4
gpt4 key购买 nike

我在 Controller 中使用$timeout,但它不起作用!

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

}]);
  • 问题是什么。

最佳答案

已更新

直接替换即可

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

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

检查Angular's doc

关于javascript - $timeout 在 angular.js 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26180401/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com