无法找出我为什么会出现喷油器错误

时间:2015-07-11 13:28:50

标签: angularjs

我在注入我的收藏品工厂时遇到错误,但无法弄清楚我哪里出错:

错误:[$ 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);

            });

        }
    ]);

1 个答案:

答案 0 :(得分:1)

我想你不应该在工厂申报中注入$scope。只需改变

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

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

工厂声明不应依赖于控制器$scope