Loading ...

Http Service And Promises

Hello everybody,

today another glimpse from the AngularJS world which I can name of how to get something from server.

So, imagine that you see following code in your controller:

 

var OrderController = function($scope, $http) {

    $scope.order = $http.get("/orders/1563");

}

and now is question, what's wrong with this? Just one very important issue, $http.get returns a promise, not the response itself. So in order to make it work correctly another approach will be more correct:

var OrderController = function($scope, $http) {

    var promise = $http.get("/orders/1563");

    promise.then(function(response){

      $scope.order = response.data;

          });

}

Why second approach is better? One of the reasons because promise give you guarantee that you'll receive data and display them correctly.

Ready to take your Acumatica development to the next level? Just like ensuring your AngularJS code retrieves data efficiently with promises, your Acumatica system can be optimized and tailored to meet your unique business needs. Whether it's custom integrations, workflows, or enhancements, our team is here to help. Leave a customization request today and let us transform your Acumatica experience into a seamless, promise-delivering solution!

Be the first to rate this post

  • Currently 0.0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5