Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I'm using an angular directive (angucomplete-alt) to generate a list of suggestions as I type into ta field. I have an issue that if I make the request using $http like below the directive picks up the data and displays it.

 return $http.get(
            myurl,
            {
                params: {
                    code: strQuery.toUpperCase()
                }
            }
        );

Alertnatively, if I return the data in a promise the directive just keep giving me an error. How can I get to this work properly as it seems like even though I'm calling the same endpoint I get way different responses

 return service.mymethod(strQuery)
            .then(function(data) {

               console.log(data);

        });
share|improve this question
    
put the code of the service, otherwise we can't understand what it does – Gianmarco Dec 4 '15 at 14:13
    
you might have some line xx.data where xx is undefined. – Hacketo Dec 4 '15 at 14:14
    
give some more lines of code so that we can help you. – katmanco Dec 4 '15 at 14:16
    
What exactly is the problem? Is the service returning different responses? – sjokkogutten Dec 4 '15 at 18:17

Although it is unclear what you are trying to achieve this is one way to call a service:

var app = angular.module('myApp', []);
app.controller('myController', function($http) {
  $http.get(myUrl, { params: {  code: strQuery.toUpperCase() }})
  .then(
    function (response, status) { // on success
      console.log(response);
    }, 
    function(error, status){ // on error
      console.log(error);
  });
}); 

$http.get returns a promise which is a pattern for handling asynchronous operations. A promise runs asynchronously and return values (on success or on error) when they are done processing.

share|improve this answer
    
thanks for getting back to me guys. I'm using this angular plugin. github.com/ghiden/angucomplete-alt, it has a service build in. I'm thinking that it's already returning a promise when it's making a request, this is why i'm seeing some errors. – Jimi Dec 4 '15 at 19:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.