0
我對JS世界有點新鮮,所以我在努力解決我做錯了什麼。我的wordpress API示例數據無效。任何想法我做錯了:Ionic/AngularJS&Wordpress API
app.controller('FeedCtrl', function($http, $scope, $ionicLoading) {
console.log("Loading FeedCtrl");
$scope.stories = [];
function loadStories(params, callback) {
$http.get('http://public-api.wordpress.com/rest/v1/freshly-pressed/', {params: params})
.success(function(response) {
var stories = [];
angular.forEach(response.data.children, function(child) {
stories.push(child.data);
});
callback(stories);
});
}
$scope.loadOlderStories = function() {
var params = {};
if ($scope.stories.length > 0) {
params['after'] = $scope.stories[$scope.stories.length - 1].name;
}
loadStories(params, function(olderStories) {
$scope.stories = $scope.stories.concat(olderStories);
$scope.$broadcast('scroll.infiniteScrollComplete');
});
};
$scope.loadNewerStories = function() {
var params = {'before': $scope.stories[0].name};
loadStories(params, function(newerStories) {
$scope.stories = newerStories.concat($scope.stories);
$scope.$broadcast('scroll.refreshComplete');
});
};
似乎沒有加載任何數據。我錯過了什麼嗎?抱歉。 –
你能檢查你的控制檯是否有任何錯誤?也許你會得到這樣的:'XMLHttpRequest無法加載'。 – mhx
沒有看到任何javascript錯誤,只有幾個CSS問題。 –