2015-09-27 74 views
1

我試圖通過角廠從遠程服務器獲取JSON。但是,當我調用get方法從服務我得到一個錯誤:角廠不返回方法

TypeError: Events.getEvents is not a function

我的工廠代碼:

angular.module('starter.services', []).config(function($httpProvider) { 
    delete $httpProvider.defaults.headers.common['X-Requested-With'];}) 
.factory('Events', function($http) { 
    return { 
     getEvents : function() { 
     return $http({ 
      url: 'http://cronicls.ru/events', 
      method: 'GET', 
      params: { startDate: '2015-09-03', endDate: '2015-09-18' } 
    }); 
    }, 
}; 
}); 

控制器代碼:

.controller('EventListCtrl', function($scope, $http, Events) { 
    Events.getEvents().success(function(data){ 
    console.log(data); 
    }) 
} 
); 

有什麼不對?

+0

你有退出什麼被注入功能後,做了與.factory後您的控制器遵循? – christopher

+0

@christopher號我能做到嗎? – whois42

+0

看起來你忘了在你的控制器中聲明依賴關係['$ scope','$ http','Events'] –

回答

0

嘗試在.factory除去末端的分號,並確保工廠就像你的.config