超时 AngularJS 中的未定义函数
undefined function in timeout angularjs
我有以下控制器:
app.controller('ListeSASController', function($scope, $rootScope, $routeParams, $location, userService, RefreshSASServices, $timeout){
this.IsUserLogged = function()
{
return userService.user().isLogged;
};
var promise = $timeout(RefreshSASServices.RafraichirSAS(), 100);
this.getSAS = function(){
return RefreshSASServices.getSAS();
};
$scope.$on('$locationChangeStart', function(){
RefreshSASServices.ArreterLesRafraichissements();
});
});
提供以下服务:
app.service('RefreshSASServices', function($http, userService, serverConfigService, $q, $timeout, $translate, constantsServices) {
var listeSAS = [];
var $this = this;
var promiseRefreshSAS;
// Getters
this.getSAS = function()
{
return listeSAS;
};
//Setters
this.clearDatas = function()
{
listeSAS = [];
};
// Communication with the server
$this.getServerUri = function()
{
return serverConfigService.getServerUri()+"majsvc/";
};
// Fonctions de rafraichissement
$this.ArreterLesRafraichissements = function()
{
if(promiseRefreshSAS !== undefined)
$timeout.cancel(promiseRefreshSAS);
};
$this.GetSASFromServer = function()
{
var promises;
if(userService.user().isLogged)
{
var uri = $this.getServerUri() + "getAllSAS/"+userService.user().UserObject._id;
promises = $http.get(uri)
.success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
return data;
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
return "";
});
}else{
promises = $q.when(!userService.user().isLogged)
}
return promises;
};
$this.RafraichirSAS = function () {
// functions that call
$this.GetSASFromServer()
.then(function(promise){
if(promise !== undefined && promise.data !== undefined)
{
listeSAS = promise.data;
//alert('refreshing the SAS list:' + JSON.stringify(listeSAS));
}else listeSAS = [];
promiseRefreshSAS = $timeout($this.RafraichirSAS, 3000);
})
.catch(function(error)
{
console.error("Error :", error);
promiseRefreshSAS = $timeout($this.RafraichirSAS, 7000);
});
};
});
当我使用路由加载我的页面时:
.when('/listeSAS', {
templateUrl : './includes/sas/liste_sas.html',
controller : 'ListeSASController',
controllerAs : 'controller'
})
一切正常,如果我的数据在服务器上发生变化,它会在 UI 上更新,我的 UI 也会显示我想要的内容。一切都很好,除了当页面加载时我收到以下错误:
TypeError: undefined is not a function
at file:///includes/libs/angular.js:14305:28
at completeOutstandingRequest (file:///includes/libs/angular.js:4397:10)
at file:////includes/libs/angular.js:4705:7
这是 Angular 的函数"超时",第 14305 行是:
try {
deferred.resolve(fn());
} catch(e) {
deferred.reject(e);
$exceptionHandler(e);
}
finally {
delete deferreds[promise.$$timeoutId];
}
为什么角度会抛出这个异常?我做错了什么?要知道 :在我的登录页面上,我设置了 2 个超时,我不会停止,因为它们刷新了"全局"变量,例如私人消息的数量。尽管有错误,但两个超时仍然有效。
我将节点 webkit 与我的应用程序一起使用,当我打开此路由时(5-10 秒后),它可能崩溃了三分之一。
谢谢你的帮助。
是你调用 RafraichirSAS(),它返回 undefined 而不是传入函数?
例如,代替
$timeout(RefreshSASServices.RafraichirSAS(), 100);
做
$timeout(RefreshSASServices.RafraichirSAS, 100);
相关文章:
- Jquery未定义函数正在停止其他操作
- 在不破坏未定义函数的情况下,对多个视图使用单个js文件
- Uncaught ReferenceError:尝试在Android网络视图中访问时未定义函数
- jQuery文件上传和验证未定义函数
- 引用错误:未定义函数-Firefox
- res.render中出错,未定义函数
- 神秘的未定义函数
- 尝试使用函数和Ajax修改值时未定义函数
- 引用错误:未定义函数
- ReferenceError:未定义函数
- 在 Angular JS 中使用 ng-include 的未定义函数
- 未捕获的引用错误:未定义函数
- j查询工具提示引发错误:未定义函数
- 未捕获的引用错误: 未定义单击世界 -- 未定义函数
- JS:引用错误:未定义函数
- 茉莉花未定义函数
- Javascript 错误:未捕获的引用错误:未定义 [函数]
- 未定义函数
- 尽管 js 文件引用在标头中,但未定义函数
- Javascript 未定义函数错误