通過

2016-03-14 62 views
0

我創建的離子移動應用程序時,他們有一些未讀郵件從他們的Office 365帳戶,將通知該應用程序的用戶的Office 365應用程序(離子移動應用程序)通知有未讀郵件。我花了數小時在這段代碼中,試圖找出它出錯的地方。如果任何人都可以找到一個理由,爲什麼這段代碼不工作,那將是非常讚賞。謝謝。通過

(function() { 
'use strict'; 

angular.module('app365').controller('homeCtrl', ['$scope', '$stateParams', '$ionicLoading', '$ionicPopup', 'app365api', homeCtrl]); 

function homeCtrl($scope, $stateParams, $ionicLoading, $ionicPopup, app365api) { 
    var vm = this; 
    var outlookClient; 

    // Get mail list. 
    function getMails() { 
     var filterQuery = ''; 

     // Get all mails flagged as important. 
     if (typeof $stateParams.important != 'undefined') { 
      getImpMails(); 
      return; 
     } 

     // Get all unread mails. 
     if (typeof $stateParams.unread != 'undefined') { 
      filterQuery = 'IsRead eq false'; 
     } 

     NProgress.start(); 
     // Fetch Inbox folder 
     outlookClient.me.folders.getFolder("Inbox").messages.getMessages().filter(filterQuery).fetch() 
      .then(function (mails) { 
       // Get current page. Use getNextPage() to fetch next set of mails. 
       vm.mails = mails.currentPage; 
       $scope.$apply(); 
       NProgress.done(); 
      }); 
    }; 
    if ($scope.result() == null) { 
     null; 
    } else { 
     $ionicPlatform.ready(function() { 

      $ionicPopup.confirm({ 
       title: "You have unread mail", 
      }) 
      .then(function (result) { 
       if (!result) { 
        ionic.Platform.exitApp(); 
       } 
      }); 
     } 

    ) 
    } 
} 
} 

) 

Error: [ng:areq] Argument 'homeCtrl' is not a function, got undefined

這是錯誤我收到即使homeCtrl是一個函數,已經被引用。

回答

0

你缺少在最末尾的()是調用您IIFE。因此,控制器沒有被註冊,因爲該功能從未運行。

變化

(function() { 
    'use strict'; 

    angular.module('app365').controller('homeCtrl', ['$scope', '$stateParams', '$ionicLoading', '$ionicPopup', 'app365api', homeCtrl]); 

    function homeCtrl($scope, $stateParams, $ionicLoading, $ionicPopup, app365api) { 
     // code removed for clarity 

    } 
    } 
) 

(function() { 
    'use strict'; 

    angular.module('app365').controller('homeCtrl', ['$scope', '$stateParams', '$ionicLoading', '$ionicPopup', 'app365api', homeCtrl]); 

    function homeCtrl($scope, $stateParams, $ionicLoading, $ionicPopup, app365api) { 
     // code removed for clarity 

    } 
})(); 
//^^ missing braces 
+0

謝謝你,這已經得到了過去的錯誤。 下一步是設法得到這個工作 –

+0

*「不起作用」 *遠遠的問題陳述太寬泛 – charlietfl