javascript - Dynamic variable name of scope -



javascript - Dynamic variable name of scope -

i seek define dynamic variable name in angularjs foreach, :

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; }); });

so, it's doesn't work , have error : cannot set property 'feed1' of undefined

what's right syntax ?

does $scope object have window property? if yes, go maxim's answer. if not, seek this:

angular.foreach($scope.posts, function (item) { // counter increment counter++; var idpage = 'feed' + counter; feedservice.parsefeed(url).then(function(res) { $scope[idpage] = res.data.responsedata.feed.entries; }); });

edit:

working plunkr: http://plnkr.co/edit/evljkisplwkpcyag7l8w?p=preview

javascript angularjs syntax

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -