Search code examples
javascriptangularjsangularjs-factory

Change URL in factory with input value with AngularJS


I want change my url parameter, starting search from a input.

I need change like for example:

return $http({
    url:'http://my-api.com/api/teste.php?' + 'input-value',
    method:'GET'
})

and this update after I change again my input!

currently I have in my code this:

.factory('netflixService', netflixService);

function netflixService($http, $log) {

   var API = 'http://netflixroulette.net/api/api.php?';
   $log.debug(API);

  return {
    getApi: function() {
        return $http({
            url:API,
            method:'GET'
        })
    }
  };
}

And I caught in this part :(

thks!


Solution

  • In your getApi method, take an argument. For example:

    return {
        getApi: function(inputValue) {
            return $http({
                url:API + inputValue,
                method:'GET'
            })
        }
      };
    

    Then you can call it in a controller like:

    netflixService.getApi('foobar');