Slidebox & JSON

Here is my app.js:

(function() {

var app = angular.module('myappname', ['ionic', 'angularMoment','LocalStorageModule']);

   app.config(function($stateProvider, $urlRouterProvider) {
        $stateProvider.state('index', {
            url : '/',
            templateUrl : 'index.html',
            controller : 'MainController'
        });
        $stateProvider.state('list', {
          url: '/list',
          templateUrl: 'templates/list.html'
        });
        $stateProvider.state('edit', {
          url: '/edit/:noteId',
          templateUrl: 'templates/edit.html',
          controller: 'EditCtrl'
        });
         $stateProvider.state('add', {
          url: '/add',
          templateUrl: 'templates/edit.html',
          controller: 'AddCtrl'
        });
         $stateProvider.state('notes', {
          url: '/notes',
          templateUrl: 'templates/notes.html'
        });
          $stateProvider.state('posts', {
          url: '/posts',
          templateUrl: 'templates/posts.html',
          controller: 'WordCtrl'
        });
        $urlRouterProvider.otherwise("/");
    });

var notes = [];

function getNote(noteId) { for (var i = 0; i < notes.length; i++) { if (notes[i].id === noteId) { return notes[i]; } } return undefined; }

function updateNote(note) {
for (var i = 0; i < notes.length; i++) {
  if (notes[i].id === note.id) {
    notes[i] = note;
    return;
  }
}

}

function createNote(note) { notes.push(note); }

app.controller('NotesCtrl', function($scope) {

$scope.notes = notes;

});

app.controller('EditCtrl', function($scope, $state) {

$scope.note = angular.copy(getNote($state.params.noteId));

$scope.save = function() { updateNote($scope.note); $state.go('notes'); };

});

app.controller('AddCtrl', function($scope, $state) {

$scope.note = { id: new Date().getTime().toString(), title: '', description: '' };

$scope.save = function() { createNote($scope.note); $state.go('notes'); };

});

app.run(function($ionicPlatform) { $ionicPlatform.ready(function() { if(window.cordova && window.cordova.plugins.Keyboard) { cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); } if(window.StatusBar) { StatusBar.styleDefault(); } }); });

}());


Here is the js that isn't working:

angular.module('myappname')

.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 = 'http://scottbolinger.com/wp-json/wp/v2/';

})

.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);

};

})

.controller('PostCtrl', function($scope, $stateParams, DataLoader, $ionicLoading, $rootScope, $sce ) {

$ionicLoading.show({ noBackdrop: true });

var singlePostApi = $rootScope.url + 'posts/' + $stateParams.postId;

DataLoader.get( singlePostApi ).then(function(response) { $scope.post = response.data; // Don't strip post html $scope.content = $sce.trustAsHtml(response.data.content.rendered); $ionicLoading.hide(); }, function(response) { console.log('error', response); });

});

/r/ionic Thread Parent