jo v
jo v

Reputation: 302

Can't find out why i'm getting an injector error

I am getting an error on injecting my collections factory, but can't figure out where I went wrong:

Error: [$injector:unpr] http://errors.angularjs.org/1.3.0/$injector/unpr?p0=%24scopeProvider%20%3C-%20%24scope%20%3C-%20collections

  'use strict';

    var thangular = angular.module('thangular', ['ngAnimate']);

    thangular.config(function ($interpolateProvider,$httpProvider) {
        $interpolateProvider.startSymbol('[[').endSymbol(']]');
        $httpProvider.defaults.useXDomain = true;
    });

    thangular.factory('collections', ['$scope', '$http', '$q',
        function ($scope, $http, $q) {

            return {

                all: function () {
                    var deferred = $q.defer();
                    var request = $http({
                        method: 'GET',
                        url: '/collections.json',
                    });
                    request
                        .success(function (result) {
                            deferred.resolve(result.content);
                        })
                        .error(function (error) {
                            deferred.reject(error);
                        });

                    return deferred.promise;
                }

            };
        }
    ]);

    thangular.controller('mainCtrl', ['$scope', 'collections',
        function ($scope, collections) {

            collections.all().then(function (data) {

                console.log(data);

            });

        }
    ]);

Upvotes: 0

Views: 104

Answers (1)

Vineet
Vineet

Reputation: 4645

I suppose you shouldn't inject $scope in factory declaration. Just change

thangular.factory('collections', ['$scope', '$http', '$q',

to

 thangular.factory('collections', ['$http', '$q',

Factory declaration should not dependent upon controllers $scope.

Upvotes: 1

Related Questions