简体   繁体   中英

Angular factory doesn't return method

I trying to get JSON from remote server through angular factory. But when i call get method from service I get an error:

TypeError: Events.getEvents is not a function

My factory code:

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 code:

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

What is wrong?

尝试在.factory的结尾处删除分号,并确保控制器在出厂后仍然遵循,就像在.config之后使用.factory一样

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM