0

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", } }; 
2
  • what do you mean by ` How to give this in a array.`?CommentedApr 7, 2017 at 5:02
  • if the below resolved your issue accept the answer.CommentedJul 20, 2022 at 21:33

2 Answers 2

3

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", }] }; 
0
    1

    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>

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.