如何纠正写入离子控制器?

时间:2016-09-06 08:52:40

标签: javascript angularjs json ionic-framework buddypress

您好我的控制器有问题。我尝试使用JSON API从Buddypress获取朋友。它的http://hannation.me/api/buddypressread/friends_get_friends/?username=adminara&insecure=cool

但是,当我试图在我的应用程序中获取它时它不起作用。

这是我的控制器

// Friends Controller
.controller('FriendsCtrl', function($scope, $rootScope, $state, $ionicLoading, PostService) {
  $scope.posts = [];
  $scope.friends = [];
  $scope.page = 1;
  $scope.totalPages = 1;

  $scope.doRefresh = function() {
    $ionicLoading.show({
      template: 'Loading posts...'
    });

    //Always bring me the latest posts => page=1
    PostService.getUserFriends(1)
    .then(function(data){

      $scope.totalPages = data.pages;
      $scope.posts = PostService.shortenPosts(data.posts);

      $ionicLoading.hide();
      $scope.$broadcast('scroll.refreshComplete');
    });
  };

  $scope.loadMoreData = function(){
    $scope.page += 1;

    PostService.getUserFriends($scope.page)
    .then(function(data){
      //We will update this value in every request because new posts can be created
      $scope.totalPages = data.pages;
      var new_posts = PostService.shortenPosts(data.posts);
      $scope.posts = $scope.posts.concat(new_posts);

      $scope.$broadcast('scroll.infiniteScrollComplete');
    });
  };


  $scope.doRefresh();

})

这是我的服务

  this.getUserFriends = function(friends){
    var deferred = $q.defer();

      $http.jsonp(WORDPRESS_API_URL + 'buddypressread/friends_get_friends/?username=adminara' +
    '&insecure=cool' +
      '&type=full' +
      '&callback=JSON_CALLBACK')

  .success(function(data) {
      deferred.resolve(data);
    })
    .error(function(data) {
      deferred.reject(data);
    });

    return deferred.promise;
  };

这是我的HTMl

    <ion-list ng-repeat="friend in friends">
      <ion-item>
        <ion-avatar item-left>
          <img class="friends-avatar" src="{{friend.avatar}}">
        </ion-avatar>
        <h2>{{friend.friends.username}}</h2>
        <h3>{{friend.mail}}</h3>
      </ion-item>
    </ion-list>

我的代码有什么问题?错误在哪里?

0 个答案:

没有答案