I’m going to sleep now.
By the way an error 404 is probably not caused by a CSP, you should look at the URL that failed to get a clue.
Thank you for your help.
Not sure if you or anyone else is around, but which controller do I use on my posts.html to grab the wordpress blogs?
I have WordCtrl and PostsCtrl
angular.module(‘mybodyapp’)
.controller(‘WordCtrl’, function($scope, $timeout, $rootScope) {
// With the new view caching in Ionic, Controllers are only called
// when they are recreated or on app start, instead of every page change.
// To listen for when this page is active (for example, to refresh data),
// listen for the $ionicView.enter event:
//$scope.$on(’$ionicView.enter’, function(e) {
//});
// Enter your site url here, leaving the /wp-json/wp/v2 part. You must have the WP-API v2 plugin activated on this site
$rootScope.url = ‘https://public-api.wordpress.com/rest/v1/freshly-pressed/’;
})
.controller(‘PostsCtrl’, function( $scope, $http, DataLoader, $timeout, $ionicSlideBoxDelegate, $rootScope ) {
console.log('PostsCtrl');
$scope.loadPosts = function() {
DataLoader.get( $rootScope.url + 'posts' ).then(function(response) {
$scope.posts = response.data;
console.log( response.data );
}, function(response) {
console.log('error', response);
});
}
// Load posts on page load
$scope.loadPosts();
paged = 2;
$scope.moreItems = true;
// Load more (infinite scroll)
$scope.loadMore = function() {
if( !$scope.moreItems ) {
return;
}
var pg = paged++;
$timeout(function() {
DataLoader.get( $rootScope.url + 'posts' + '?page=' + pg ).then(function(response) {
angular.forEach( response.data, function( value, key ) {
$scope.posts.push(value);
});
if( response.data.length <= 0 ) {
$scope.moreItems = false;
}
}, function(response) {
$scope.moreItems = false;
console.log('error');
});
$scope.$broadcast('scroll.infiniteScrollComplete');
$scope.$broadcast('scroll.resize');
}, 1000);
}
$scope.moreDataExists = function() {
return $scope.moreItems;
}
// Pull to refresh
$scope.doRefresh = function() {
console.log('Refreshing!');
$timeout( function() {
$scope.loadPosts();
//Stop the ion-refresher from spinning
$scope.$broadcast('scroll.refreshComplete');
}, 1000);
};
})
Hey, maybe it is too late but instead of hardcoding your Http calls you can use this lib: https://github.com/shprink/wp-api-angularjs
Cheers