我正在尝试使用WordPress rest api插件和$http服务将我的angular应用程序连接到wordpress CM。然而,由于某些原因,数据return.Can没有人提供使用wordpress rest api插件为wordpress检索数据的正确方法吗?
下面我列出了我的代码,其中包括我的html和JavaScript。此外,我还列出了我正在尝试获取测试数据的本地rest api。
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.2/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-sanitize/1.6.2/angular-sanitize.js"></script>
</head>
<body>
<div class="masthead" np-app="myApp">
<div class="item">
<div class="masthead-content">
<div class="copy">
<div class="container">
<div class="row">
<div class="col-md-6" ng-controller="Ctrl">
<div ng-repeat="post in posts | limitTo: 1">
<h2 ng-bind-html="post.title.rendered">{{posts}}</h2>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
var app = angular.module('myApp', ['ngSanitize']);
app.controller('myCtrl', function($http, $scope) {
$http.get("http://localhost/wp/wp-json/wp/v2/posts/4").success(function(data) {
$scope.posts = data;
});
});
</script>
发布于 2018-06-25 02:33:23
调用WordPress的rest API没有问题
$http.get('https://yourblog.com/wp-json/wp/v2/posts/?categories=1&per_page=2&orderby=id&order=asc&page=1').
then(function(response) {
console.log(response);
$scope.posts = response.data;
});
此代码在我的AngularJS或ionic应用程序中运行
<div ng-repeat="post in posts">
<h2>{{post.title}}</h2>
</div>
https://stackoverflow.com/questions/42257132
复制相似问题