简体   繁体   English

WordPress的主题angularJS承诺

[英]Wordpress theme angularJS promises

I have a wordpress angularjs theme but it's not loading content using promises. 我有一个wordpress angularjs主题,但它没有使用promise加载内容。 I'm trying to do a few HTTP requests but I can't figure out an easy way of achieving it. 我正在尝试执行一些HTTP请求,但是我想不出一种简单的方法来实现它。

I have looked at tutorials on promises and factories but anything I try results in an error. 我看过关于Promise和Factory的教程,但是我尝试的任何操作都会导致错误。 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. 上面的第二个和第三个HTTP请求在第一个请求的回调上被调用。

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){
      });
   });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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