javascript - AngularJS: What is the best way to add JSON that ends with different ids inside $http.get()? -
i trying display items json, , has array of different ids @ end of url(/api/messages/:messageid). example, /api/messages/12345 getting {"subject":"subject12345","body":"body12345","id":"12345"}.
my thought looping through data , adding @ end of 'api/message/' job. can't figure out how define data before $http.get.
so best way define data make work? or there other way solve this?
angularjs code:
var countryapp = angular.module('countryapp',[]); countryapp.controller('countryctrl', function($scope, $http){ for(i=0;i<data.length;i++){ var messageid = data[i].id; console.log(messageid); // data undefined here } $http.get('/api/messages/' + messageid ).success(function(data){ $scope.messages = data; $scope.expand = function (message) { angular.foreach($scope.messages, function (currentitem){ currentitem.showfull = currentitem == message && !currentitem.showfull; }); }; }); }); json:
// api/messages/12345: {"subject":"subject12345","body":"body12345","id":"12345"} // api/messages/123456789 {"subject":"subject123456789","body":"body123456789","id":"123456789"} // , on...
it sounds you're trying this:
$http.get('/api/messages/' + messageid).success(function(data) { (obj in data) { data[obj] += messageid; } //do data. });
Comments
Post a Comment