2016-03-11 42 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