Let's say I have a foreign API URL like http://something.com/name/age/gender
, where "name", "age" and "gender" are parameters.
As I need to retrieve that data from my Angular 1 App, I created a .service, that should use $http in order to get it. But... such service needs to be called from the controller, and needs to receive parameters.
How do I set all that and how do I call it from the controller?
The only thing I have in the service is this:
export const SearchPersonService = ($http) => {
'ngInject';
return $http.get('someUrl');
};
and the controller has the code below:
SearchPersonService.success(
data => this.persons = data
).error(
error => alert('err')
);
Solved it! The only thing I had to do was wrapping the $http object into a function that takes the necessary parameters: