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
Post a Comment