2016-03-11 41 views
0

當我嘗試運行此:AngularJs功能沒有發現

(function() { 
     'use strict'; 
     // 1. Module definieren 
     angular.module('myApp') 
     .controller('homeController',homeController); 

     homeController.$inject = ['employeeFactory']; 
     function homeController(employeeFactory) { 
      var vm = this; 
      vm.getEmployees = function() { 
       employeeFactory.getEmployees() 
         .then(function(employee) { 
          console.log(employee); 
          vm.employees = employee.result; 
         }); 
      }; 

     } 
    })(); 

我收到以下錯誤在我的控制檯:

angular.js:13307 TypeError: employeeFactory.getEmployees is not a function 
    at homeController.vm.getEmployees (homeController.js:11) 
    at fn (eval at <anonymous> (angular.js:14157), <anonymous>:4:280) 
    at expensiveCheckFn (angular.js:15146) 
    at callback (angular.js:24614) 
    at Scope.$eval (angular.js:16888) 
    at Scope.$apply (angular.js:16988) 
    at HTMLButtonElement.<anonymous> (angular.js:24619) 
    at defaultHandlerWrapper (angular.js:3394) 
    at HTMLButtonElement.eventHandler (angular.js:3382) 

我在做什麼錯。

+1

你能包括替換它的工廠代碼,而運行此代碼? –

+0

問題是'employeeFactory',沒有代碼,不能肯定有幫助 –

回答

1

檢查工廠employeeFactory的聲明。

工廠存在,但好像getEmployees不存在或者您沒有將其聲明爲函數。

如果你想在這一些幫助添加在您宣佈廠

1

你在錯誤的方式定義模塊的代碼,

angular.module('myApp') 

angular.module('myApp',[]) 
+0

這是可能的。我已經在我的app.js文件中做到了。 – Jamie

+0

這與它無關。您將看到的錯誤是模塊「{0}」不可用!您拼錯了模塊名稱或忘記加載模塊名稱。如果註冊模塊確保您指定依賴關係作爲第二個參數。 – skubski