Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 为什么角度控制器中的数据覆盖?_Angularjs_Ionic Framework - Fatal编程技术网

Angularjs 为什么角度控制器中的数据覆盖?

Angularjs 为什么角度控制器中的数据覆盖?,angularjs,ionic-framework,Angularjs,Ionic Framework,这可能是一个愚蠢的问题,但我不明白为什么会发生这种情况。我在一个Ionic应用程序中工作,我有一个控制器,其中注入了多个服务,这些服务基本上是向API URL发出http请求的承诺。这很好,但我需要添加另一个服务并将其注入控制器,但当我这样做时,以前加载的所有数据将不再显示 我删除了一个使用另一个服务的函数,它可以工作(反之亦然),但我需要这两个服务。似乎范围中的某些内容正在被覆盖,但我不明白为什么会发生这种情况。我希望你们能帮我,伙计们 这是控制器的代码。我不包括服务代码,因为没关系。我要使用

这可能是一个愚蠢的问题,但我不明白为什么会发生这种情况。我在一个Ionic应用程序中工作,我有一个控制器,其中注入了多个服务,这些服务基本上是向API URL发出http请求的承诺。这很好,但我需要添加另一个服务并将其注入控制器,但当我这样做时,以前加载的所有数据将不再显示

我删除了一个使用另一个服务的函数,它可以工作(反之亦然),但我需要这两个服务。似乎范围中的某些内容正在被覆盖,但我不明白为什么会发生这种情况。我希望你们能帮我,伙计们

这是控制器的代码。我不包括服务代码,因为没关系。我要使用的服务是followService,我为followService工作而删除的服务是profileInformationService

angular.module('app.controllers')

.controller('profileCtrl', function($scope, $ionicModal, $controller, $state, $ionicPopup, $ionicHistory, store, userDataService, profileInformationService, feedService, followService){
  $ionicModal.fromTemplateUrl('templates/post_detail.html', {
    scope: $scope,
    animation: 'slide-in-up'
  }).then(function(modal){
    $scope.modal = modal;
  });
  $controller('utilsCtrl', { $scope: $scope });
  $scope.login_required = true;
  $ionicHistory.clearHistory();
  $scope.upload = {};
  $scope.profile = {followers: 0, following: 0};
  $scope.indicator = '';
  $scope.following = {};
  $scope.upload.profilePicture = null;
  $scope.charity = store.get('charity_name');
  $scope.refreshFeed = function(){
    userDataService.getUserData().then(function(user){
      $scope.user = user;
      console.log(user);
      $scope.wallet = store.get('wallet');
      feedService.getPosts($scope.user.username).then(
        function(response){
          //for (var item in response.data){
          //  response.data[item].total_description = response.data[item].description
          //  if (response.data[item].description.length > 50){
          //    response.data[item].description = response.data[item].description.substring(0, 47)+"..."
          //  }
          //};
          $scope.feed = organize_posts(response, 'peeks');
          // followService.getFollowingList().then(
          //   function (list) {
          //     console.log(list)
          //   },function(error){
          //     console.log("Re Paila")
          //   } 
          // );

          profileInformationService.getProfileInfo(user.username).then(
            function(data){
              $scope.profile = data.data;
              feedService.getKeeps().then(
                function(keeps){
                  //for (var item in keeps.data){
                  //  keeps.data[item].total_description = keeps.data[item].description
                  //  if (keeps.data[item].description.length > 50){
                  //    keeps.data[item].description = keeps.data[item].description.substring(0, 47)+"..."
                  //  }
                  //};
                  keeps = organize_posts(keeps, 'keeps');
                  //console.log(keeps)
                  $scope.feed.data = $scope.feed.data.concat(keeps.data);
                  console.log($scope.feed.data)
                });
            });
        }
        );
    }, function(error){
      $state.go('login');
    }).finally(function(){
      $scope.$broadcast('scroll.refreshComplete'); 
    });
  };
  $scope.refreshFeed();



  organize_posts = function(items, variable){
  for (var item in items.data){
    if(variable == 'peeks'){
      items.data[item].peeks = true
    }else if(variable == 'keeps'){
      items.data[item].keeps = true
    }
    items.data[item].total_description = items.data[item].description
    if (items.data[item].description.length > 50){
      items.data[item].description = items.data[item].description.substring(0, 47)+"..."
    }
  };
  return items;
  }

  $scope.submit = function(){
    userDataService.updateUserData($scope.user).then(function(data){
      alertPopup = $ionicPopup.alert({
        title: 'Success',
        template: 'User data was updated.'
      });
      $state.go('tabsController.profile');
    }, function(error){
      alertPopup = $ionicPopup.alert({
        title: 'Error',
        template: 'Data could not be updated.'
      });
    });
  };

  $scope.openFileDialog = function(){
    ionic.trigger('click', { target: document.getElementById('profile-picture') }); 
  };

  $scope.$watch("upload.profilePicture", function(newValue, oldValue){
    if(newValue!=null && typeof newValue.name=='string'){
      userDataService.updateProfilePicture(newValue).then(
          function(response){
            user.profile_picture = response.data.success;
          });
    }
  });
})

你可以放置一个
调试器refreshFeed()
中编写代码>并逐步完成该函数?我对这一点非常陌生,调试器是如何工作的?将
调试器放入就在您希望编译器暂停的点之前。暂停使您能够在执行函数之前查看所有变量的内容。您需要打开web开发人员控制台。您可以下载各种插件和扩展。