0

hi all i am using angularjs i am trying to do push the scope variable to another scope array i paste my code also my need my scope array look like this here i have get the value from two scope and push into one scope variable it's work fine my need is i want push the $scope.ViewGetMaterialStreams value inside the Materialselection id when i expand the id i need one array called name how to declare help how to do this

  $scope.Materialselection ={id: [?i need the Namecolumn here in array]};

  for(var i=0 ;i<$scope.BFMaterial.length;i++) {
              $scope.Materialselection.stream.push($scope.BFMaterial[i]); 
                $scope.Materialselection.stream.push($scope.ViewGetMaterialStreams[i].name); 

               }

enter image description here

here i exapnd 0 i get output id:121 look like this now my need is when i expand 0 i need to show expand 0 i want show id :12121,name:dfdf

6
  • what's the relationship between Materialselection and BFMaterial? Commented May 9, 2017 at 7:17
  • BFMaterial values from db that value will push into Materialselection Commented May 9, 2017 at 7:17
  • while pushing, is there any rule for that? or just simply by index of two array? Commented May 9, 2017 at 7:18
  • array okay @pengry now my output how came means is when check Materialselection expand id value is came correctly from $scope.Materialselection.stream.push($scope.BFMaterial[i]) now i want store name from $scope.ViewGetMaterialStreams[i].name and push into inside the id of $scope.Materialselection Commented May 9, 2017 at 7:21
  • i update my quesiton kindly refer @Pengyy Commented May 9, 2017 at 7:27

2 Answers 2

1

try this

$scope.Materialselection.stream =[];

$scope.BFMaterial.forEach(function(item, index) {
  var obj = {};
  obj.id = item.id;
  obj.name = $scope. ViewGetMaterialStreams[index].name;
  $scope.Materialselectio.stream.push(obj);
});
Sign up to request clarification or add additional context in comments.

6 Comments

when iam usign this in for loop means all value are same help!!@pengyy
try this code $scope.Materialselection =[]; var obj = {}; for(i=0 ;i<4;i++){ obj.id = i; obj.name = i; $scope.Materialselection.push(obj); }
@jose move var obj = {}; into for-loop.
@jose confirmed but I don't think you have post all relevant things such as the directive used at tr.
|
1

You can do it in following way:

$scope.Materialselection =[];
angular.forEach($scope.BFMaterial,function(item, index) {
  var obj = {
  id: item.id,
  name: $scope.ViewGetMaterialStreams[i].name
  };
  $scope.Materialselection.push(obj);
});

2 Comments

Cannot read property 'push' of undefined i get error look like this @parteek
here no changes do ?$scope.Materialselection ={id: [?i need the name column here in array]}; where i declare name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.