0

When I try to run this:

 (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;
                        });
            }; 

        }
    })();

I receive the following error in my console:

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)

What am I doing wrong.

2
  • 1
    Can you include your factory code while running this code ? Commented Mar 11, 2016 at 8:03
  • The issue is with employeeFactory and without the code, cannot certainly help Commented Mar 11, 2016 at 8:24

2 Answers 2

1

Check the declaration of your factory employeeFactory.

The factory exists but it seems like getEmployees does not exists or you didn't declare it as a function.

If you want some help on this add the code where you declare that factory

Sign up to request clarification or add additional context in comments.

Comments

1

You define module in wrong manner,

 angular.module('myApp')

Replace it with

 angular.module('myApp',[])

1 Comment

This has nothing to do with it. The error you'd see then is Module '{0}' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.