Object undefined angular

1
// app.js
$scope.result = {};
//$scope.result = [];

for (i = 0; i < object.length; i++) {
   $scope.result[i].value = object[i].value;
   $scope.result[i].justification = object[i].justification;
};

This is the error I get:

  

$scope.result[i] is "undefined"

    
asked by sirdaiz 24.03.2017 в 14:49
source

2 answers

2

You can not add properties to an object, without first creating the object itself:

$scope.result = {}

for (i = 0; i < object.length; i++) {
   $scope.result[i] = { };
   $scope.result[i].value = object[i].value;
   $scope.result[i].justification = object[i].justification;
};
    
answered by 24.03.2017 / 14:52
source
0

Try this $scope.result = []; instead of what you have $scope.result = {}; .

    
answered by 24.03.2017 в 14:51