When attempting to create a dynamic variable name within an AngularJS foreach loop, I encountered the following issue:
angular.forEach($scope.posts, function (item) {
// counter increment
counter++;
var idPage = 'feed' + counter;
FeedService.parseFeed(url).then(function(res) {
$scope.window[idPage] = res.data.responseData.feed.entries;
});
});
Unfortunately, this code is not functioning as expected and triggers the error message:
Cannot set property 'feed1' of undefined
Could someone please provide guidance on the correct syntax for achieving this task?