In the below code, 'info' object has a description, quantity, value. How to give them as an array(Indo property). How to retrieve in angular code.

details.customsDetail.itemDetails = {
                    currency : "2000USD",
                    weight : "lbs",
                    info : {                         
                        description : "descr",
                        quantity : "2",
                        value : "124",              

                     }

            };
share|improve this question
    
what do you mean by ` How to give this in a array.`? – Maximus Apr 7 at 5:02

Do you mean , indo property as array of objects?

details.customsDetail.itemDetails = {
                    currency : "2000USD",
                    weight : "lbs",
                    info : [{                         // How to give this in a array.
                        description : "descr",
                        quantity : "2",
                        value : "124",              

                     }]

            };
share|improve this answer
    
yes. How to retrieve this in angular code? – Anju Apr 7 at 5:18
    
What do you mean by retrieve in Angular code? – Ved Apr 7 at 5:21
    
Thanks for the help. I got it. – Anju Apr 7 at 5:37
    
Welcome. Happy to help. – Ved Apr 7 at 5:40

you can assign the object to a variable and later you can push it to an array.

var backUp = angular.copy($scope.details.customsDetail.itemDetails.info);

$scope.details.customsDetail.itemDetails.info = [];
$scope.details.customsDetail.itemDetails.info.push(backUp);

console.log($scope.details.customsDetail.itemDetails)

angular.module("app",[])
.controller("ctrl",function($scope){
$scope.details = {"customsDetail":{"itemDetails":{}}};

$scope.details.customsDetail.itemDetails = {
      currency : "2000USD",
      weight : "lbs",
      info : {// How to give this in a array.
          description : "descr",
          quantity : "2",
          value : "124",              

       }

  };

var backUp = angular.copy($scope.details.customsDetail.itemDetails.info);

$scope.details.customsDetail.itemDetails.info = [];
$scope.details.customsDetail.itemDetails.info.push(backUp);

console.log($scope.details.customsDetail.itemDetails)
  
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
 
</div>

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.