Javascript angular function definition

73 Views Asked by At
function callbackformeetup (data) {
  console.log(data);
}

app.service('MeetupSearch', function($http){
  this.search = function(zip, word){
    return $http.jsonp('https://api.meetup.com/find/groups?key=111111111111&sign=true&photo-host=public&zip=80202&upcoming_events=true&text=ruby&callback=callbackformeetup');
    };
});

So the above works. When I define the function above the app.service, the api call works and successfully returns me data. However, this does not work:

app.service('MeetupSearch', function($http){
   function callbackformeetup (data) {
     console.log(data);
   }

  this.search = function(zip, word){
    return $http.jsonp('https://api.meetup.com/find/groups?key=52147258472159b1938714519435029&sign=true&photo-host=public&zip=80202&upcoming_events=true&text=ruby&callback=callbackformeetup');
    };
});

What gives? Why does that not work when I define the function inside?

1

There are 1 best solutions below

1
On BEST ANSWER

Doesnt work because callbackformeetup isn't available as a global function, and thats a condition to make jsonp work