2015-07-11 81 views
0

我正在上注入我的收藏品廠一個錯誤,但無法弄清楚哪裏出了錯:不能找出爲什麼我得到的注射器錯誤

錯誤:[$注射器:unpr] http://errors.angularjs.org/1.3.0/ $噴油器/ unpr?P0 =%24scopeProvider%20%3 C-%20%24scope%20%3 C-%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

我想你不應該在工廠聲明注入$scope。只要改變

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

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

廠申報不應該依賴於控制器$scope

+0

好的,只是試了一下,它看起來像解決了。這很有趣。我之前多次注入了$ rootScope,並且工作正常。謝謝! –

+0

'$ rootScope'可以在工廠中使用,但工廠沒有自己的作用域,所以'$ scope'不能使用 –

相關問題