2013-10-23 75 views
0

我有以下代碼:如何從服務內部調用Angular Service中的函數?

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

你試過'factory.submitItem'而不是'submitItem'嗎? –

+0

是的,工作!你可以把答案作爲答案,我可以接受。 – Melina

+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) { 

      } 
     } 
    } 
相關問題