简体   繁体   中英

Wordpress theme angularJS promises

I have a wordpress angularjs theme but it's not loading content using promises. I'm trying to do a few HTTP requests but I can't figure out an easy way of achieving it.

I have looked at tutorials on promises and factories but anything I try results in an error. Can anybody show an example of something that would work?

Here's each of the requests:

$http.get('wp-json/wp/v2/posts/?filter[name]=' + $routeParams.slug)
$http.get('wp-json/theme/v1/post/' + $scope.post.id)
$http.get('wp-json/wp/v2/media/' + $scope.post.featured_image)

Here's my controller. Once I can see how it will work with promises I will be able to figure it out easier. The second and third HTTP request above are called on callback on the first request.

app.controller('Post', ['$scope', '$routeParams', '$http', 'service', function($scope, $routeParams, $http, WPService) {    
    // requests
}]);
$http.get(first_url).success(function (firstResult) {
   $http.get(second_url).success(function (secondResult) { 
      $http.get(third_url).success(function (thirdResult){
      });
   });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM