我有以下代码:
angular.module('admin')
.factory('gridService',
['$resource', 'gridSelectService', 'localStorageService',
function ($resource, gridSelectService, localStorageService) {
var factory = {
gridSetup: function ($scope) {
$scope.editRow = function (row, entityType) {
window.setTimeout(function () {
window.setInterval(function () {
submitItem($scope, $scope.modal.data);
}, 1 * 60 * 1000);
submitItem($scope, $scope.modal.data);
}, 1 * 60 * 1000);
}
submitItem: function ($scope, formData) {
}
}
}
我想从window.setTimeout和setInterval内部调用submitItem函数,但它无法识别该函数。我怎么称呼它?我尝试使用gridService.submitItem,但这也不起作用。
答案 0 :(得分:2)
你应该只尝试'factory.submitItem'而不是'submitItem'它应该可以工作。
angular.module('admin')
.factory('gridService',
['$resource', 'gridSelectService', 'localStorageService',
function ($resource, gridSelectService, localStorageService) {
var factory = {
gridSetup: function ($scope) {
$scope.editRow = function (row, entityType) {
window.setTimeout(function () {
window.setInterval(function () {
factory.submitItem($scope, $scope.modal.data);
}, 1 * 60 * 1000);
factory.submitItem($scope, $scope.modal.data);
}, 1 * 60 * 1000);
}
submitItem: function ($scope, formData) {
}
}
}