2017-07-20 26 views
-1

Ich habe Objekt erstellt edit_stat es an einen anderen Controller durch resolve-Eigenschaft zu übergeben. Aber die Eigenschaftswerte von Objekten zeigen undefined.I hatte auch die Protokollausgabe gezeigt. Das Problem, warum es so angezeigt wird, kann ich nicht sehen.Eigenschaften eines Objekts zeigen undefined

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

Bitte senden Sie uns eine [ein Minimal, Complete, und prüfbare Beispiel] (https://stackoverflow.com/help/mcve) –

+0

Dieser Code rechtfertigt nichts. Posten Sie mehr. – Kamesh

+0

@Kamesh Plz überprüfen Sie es noch einmal. –

Antwort

0

Log success.data und sehen, was vom Server zurückgesendet wird. Schauen Sie sich das Gehäuse an, da dies zu Problemen führen kann.

+0

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

+0

wenn möglich plzcheck it out –

Verwandte Themen