3

A follow up to the last rant.

Trying to get that angular working with my rest api. But frickin observables and promises. I built my angular based on the official tutorial from the angular website. Sadly that tutorial uses promises, which aren't that suited for communicating with an api. So now I'm learning/implementing observables into the angular.
BUT I'M GETTING SO MUCH ERRORS. CONFUSION IS RISING.

I need more coffee to do this. :/

Comments
  • 1
    Using rest api with promises is normal, just like fetch is a promise. What do you mean that it does not work well with your rest api? With promises you can easily chain stuff and catch errors for example:

    // RestService is just a wrapper to different $http stuff

    restService.doSomething()
    .then((response) => {
    // Do something with the response
    vm.someangularvar = response.data;
    })
    .catch((error) => {
    // Handle the error from api
    });

    BTW, this is angular 1.5 style, I haven't started angular 2 but ajax calls are the same I think..
  • 0
    @cahva Thanks for the advice. I'm still learning and didn't really do frontend before. Also, every tutorial for calling to an api thats on a remote server with the http module, used observables
  • 0
    As long as you're only expecting one result per call, promises are fine for a rest API. Learn how to do observables too, though, they're cool.

    Although they use array-like functions, they run on each result instead of each element. Understanding that concept helped me.
Add Comment