0

I keep getting errors while injecting a factory in to a controller. It worked in a case where the controller is simple. It fails when the page and the controller has special components like ng-flow or ng-grid.

var carouselController = carouselApp.controller('carouselController', ['CMSFactory', function ($scope,CMSFactory) {

// MY CODE HERE...

}
var CMSServices = angular.module('api.services', [ 'ngResource' ]);

CMSServices.factory('CMSFactory', function($http, $q) {
    var CMSService = {};

    CMSService.saveSiteInfo = function(data) {

    // MY CODE HERE...

    };

    CMSService.addSlide = function(data) {

    // MY CODE HERE...

    };

    return CMSService;
});

I get TypeError: undefined is not a function error. If I remove the factory injection code works fine.

Appreciate any help...

1 Answer 1

1

You're not declaring $scope in your array of dependencies:

Change:

var carouselController = carouselApp.controller('carouselController', ['CMSFactory', function ($scope,CMSFactory) {

To:

var carouselController = carouselApp.controller('carouselController', ['$scope', 'CMSFactory', function ($scope,CMSFactory) {
Sign up to request clarification or add additional context in comments.

1 Comment

That fixed the issue... I wan't expecting it to be that simple after looking through all blogs for couple of hours... Thanks,

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.