diegonetto / stock-dog

Tutorial on building an Angular application.
47 stars 44 forks source link

$http.jsonp(...).success is not a function angularjs. Any idea how to integrate with API by overcoming this error?? #6

Open Sahanaa opened 7 years ago

Sahanaa commented 7 years ago

This typescript error occurs while integrating with Yahoo API. I think this doesn't work with angularjs ^1.4.0.

Check the code below -

     `$http.jsonp(url + '&callback=JSON_CALLBACK')
       .success(function (data) {
      if (data.query.count) {
        var quotes = data.query.count > 1 ? data.query.results.quote : [data.query.results.quote];
        update(quotes);
        }
    })  
    .error(function (data) {
        console.log("error");
      console.log(data);
    });`
Ekus commented 6 years ago

in angularjs 1.6+ jsonp() no longer supports .success() and .error() methods, but instead single method .then(successCallback, errorCallback) (or like this: .then(function(response){...}, function(response){...}); )