2017-07-20 11 views
-1

解決プロパティを介して別のコントローラに渡すためにedit_statオブジェクトを作成しました。しかし、オブジェクトのプロパティ値はundefinedを表示しています.iはログ出力も表示しています。なぜこのように表示されているのかわかりません。オブジェクトのプロパティが定義されていない

angular.module('fitgalaxyApp').controller('userProfileCtrl', function($scope, apiService, $uibModal) { 


var url = "coaching/getUserstatsGoal/0"; 
    apiService.getDataWithToken(url, {}, 'GET').then(function(success) 
    { 
    $scope.current_stat = []; 
    $scope.goal =[]; 
    $scope.activity=""; 
    var edit_stat={}; 
     if (success.status == 200) 
     { 
      var current_stat = success.data.currentStats; 
      $scope.first_name = current_stat.first_name; 
      $scope.last_name = current_stat.last_name; 
      $scope.weight = current_stat.weight; 
      $scope.height = current_stat.height; 
      $scope.bodyfat = current_stat.bodyfat; 
      $scope.age = current_stat.age; 
      $scope.activity_level_id = current_stat.activity_level_id; 
      $scope.birthdate = current_stat.birthdate; 
      $scope.gender = current_stat.gender; 
      $scope.avatar = current_stat.avatar; 

      //Goals Data 
      var goal = success.data.goals; 
      $scope.weigh = goal.weight.quantitative.weight; 

       if(goal.weight.qualitative_entry){ 
         $scope.weight_comment = []; 
         for (var i = 0; i < goal.weight.qualitative.length; i++) { 
          $scope.weight_comment.push(goal.weight.qualitative[i].comment); 
         } 
       } 

      //nutrition data 
      $scope.calories = goal.nutrition.quantitative_day.calories; 
      $scope.protein = goal.nutrition.quantitative_day.protein; 
      $scope.carbohydrate = goal.nutrition.quantitative_day.carbohydrate; 
      $scope.fat = goal.nutrition.quantitative_day.fat; 
      $scope.water_consumed = goal.nutrition.quantitative_day.water_consumed; 

      if(goal.nutrition.qualitative_entry){ 
       $scope.nutrition_comment = []; 
       for (var i = 0; i < goal.nutrition.qualitative.length; i++) { 

        $scope.nutrition_comment.push(goal.nutrition.qualitative[i].comment); 
       } 
      } 

      //exercise data 
      $scope.calorie = goal.exercise.quantitative_week.calories; 
      $scope.aerobic_minutes = goal.exercise.quantitative_week.aerobic_minutes; 
      $scope.no_of_strength_exercises = goal.exercise.quantitative_week.no_of_strength_exercises; 

      if(goal.exercise.qualitative_entry){ 
       $scope.exercise_comment = []; 
       for (var i = 0; i < goal.exercise.qualitative.length; i++) { 
        $scope.exercise_comment.push(goal.exercise.qualitative[i].comment); 
       } 
      } 

      //sleep data 
      $scope.duration = goal.sleep.quantitative_day.day_duration; 
      $scope.bedtime = goal.sleep.quantitative_day.day_bed_time; 
      if(goal.sleep.qualitative_entry){ 
       $scope.sleep_comment = []; 
       for (var i = 0; i < goal.sleep.qualitative.length; i++) { 

        $scope.sleep_comment.push(goal.sleep.qualitative[i].comment); 
       } 
      } 

      //sunlight data 
      $scope.total = goal.sunlight.quantitative_day.total_sunlight; 
      $scope.direct = goal.sunlight.quantitative_day.direct; 
      $scope.indirect = goal.sunlight.quantitative_day.indirect; 
      if(goal.sunlight.qualitative_entry){ 
       $scope.sunlight_comment = []; 
       for (var i = 0; i < goal.sunlight.qualitative.length; i++) { 
        $scope.sunlight_comment.push(goal.sunlight.qualitative[i].comment); 
       } 
      } 


      if(parseInt($scope.activity_level_id)==1){ 
      $scope.activity = 'Sedentary'; 
      return $scope.activity; 
      } 
      else if(parseInt($scope.activity_level_id)==2){ 
      $scope.activity = 'Lightly Active'; 
      return $scope.activity; 
      } 
      else if(parseInt($scope.activity_level_id)==3){ 
      $scope.activity = 'Moderately Active'; 
      return $scope.activity; 
      } 
      else if(parseInt($scope.activity_level_id)==4){ 
      $scope.activity = 'Very Active'; 
      return $scope.activity; 
      } 
      else if(parseInt($scope.activity_level_id)==5){ 
      $scope.activity = 'Extremely Active'; 
      return $scope.activity; 
      } 
     } 

}); 
var edit_stat = { 
    'Weight': $scope.weight, 
    'Bodyfat': $scope.bodyfat, 
    'Date of Birth': $scope.birthdate, 
    'Height': $scope.height, 
    'Gender': $scope.gender, 
    'Activity Level': $scope.activity, 
} 
console.log(JSON.stringify(edit_stat)); 
console.log(edit_stat); 
/*edit_stat.weight = $scope.weight; 
edit_stat.bodyfat = $scope.bodyfat; 
edit_stat.birthdate = $scope.birthdate; 
edit_stat.height = $scope.height; 
edit_stat.gender = $scope.gender; 
edit_stat.activity = $scope.activity; 

console.log(typeof edit_stat);*/ 

$scope.editWeight = function(){ 
    $uibModal.open({ 
     templateUrl: 'templates/editWeightPopup.html', 
     controller: 'editWeightPopupCtrl', 
      resolve: { 
      weight: function() { 
      return $scope.weigh; 
      } 
     } 
     }); 
    } 
$scope.$on('weight', function(event, args) { 
    $scope.weigh = args; 
}); 

$scope.editStats = function(){ 
    $uibModal.open({ 
    templateUrl: 'templates/editStatsPopup.html', 
    controller: 'editStatsPopupCtrl', 
     resolve: { 
     edit_stat: function(){ 
      return $scope.edit_stat; 
     } 
     } 

    }) 
} 

});

Object {Weight: undefined, Bodyfat: undefined, Date of Birth: undefined, Height: undefined, Gender: undefined…}Activity Level: undefinedBodyfat: undefinedDate of Birth: undefinedGender: undefinedHeight: undefinedWeight: undefined__proto__: Object 
+1

[最小限の完全で検証可能な例](https://stackoverflow.com/help/mcve) –

+0

このコードは何も正当なものではありません。もっと投稿してください。 – Kamesh

+0

@Kamesh Plzもう一度それをチェックしてください。 –

答えて

0

ログにはsuccess.dataが記録され、サーバーから返されたものが表示されます。これがあなたの問題を引き起こしているかもしれないので、ケーシングを見てください。

+0

jsfiddle.net/Sid2411/nL6Lt83f/#&togetherjs=Aix32mNFn5 –

+0

可能であればplzcheck out –

関連する問題