I have add my code and json which I want to loop.
I have looped $scope.data using foreach loop and push to $scope.tempObj, its working fine. But when I try to loop $scope.data.policyDocumentContentCollection and push to $scope.tempObj.nested, its get console error "Cannot read property 'push' of undefine". Can I know how to push 2nd foreach data to nested array which is in $scope.tempObj.
$scope.data = [
{
"policyNo":"DBDP18S016696",
"renewalNo":"001",
"endorseNo":"001",
"productDesc":"TBD",
"policyDocumentContentCollection":[
{
"docType":"Credit Note1"
},
{
"docType":"Tax Invoice1"
}
]
},
{
"policyNo":"DBDP18S016697",
"renewalNo":"001",
"endorseNo":"001",
"productDesc":"TBD",
"policyDocumentContentCollection":[
{
"docType":"Credit Note1"
},
{
"docType":"Tax Invoice1"
}
]
},
{
"policyNo":"DBDP18S016698",
"renewalNo":"001",
"endorseNo":"001",
"productDesc":"TBD",
"policyDocumentContentCollection":[
{
"docType":"Credit Note1"
},
{
"docType":"Tax Invoice1"
}
]
}
]
$scope.tempObj = [];
angular.forEach($scope.data, function (data) {
$scope.tempObj.push({
'id': data.policyNo,
'renewalNo': data.renewalNo,
'endorsementNo': data.endorseNo,
'product': data.productDesc,
'insuredName': data.holderName,
'periodOfInsurance': data.fromDate + ' to ' + data.toDate,
'nested': []
});
angular.forEach($scope.data.policyDocumentContentCollection, function (docs) {
$scope.tempObj.nested.push({
docName: docs.docType
})
});
});
$scope.tempObj.nesteddoesn't exist.$scope.tempObjis an array.