Reputation: 1032
I am not able to update my ng-repeat list after I do PUT request. Service works fine.
controller.js
teamData.updateTeam(team.id, teamObj, function(res) {
console.log('Success');
});
service.js
teamService.updateTeam = function(teamId, param, callback) {
var req = {
method: 'PUT',
url: '/team' + teamId,
headers: {
'Content-Type': 'application/json'
},
'data': param
};
return $http(req).then(function(res){
callback(res);
}, function(err){
callback(err);
});
};
teamRoute.js
app.put('/team/:id', function(request, response) {
var options = {
host: reqParam.hostFramework,
path: reqParam.path + '/team/' + request.params.id,
method: 'PUT',
headers: {
'token': reqParam.token,
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(JSON.stringify(request.body))
}
};
var resString = '';
var req = https.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function(d) {
resString += d;
});
res.on('end', function() {
response.send(resString);
});
});
req.write(JSON.stringify(request.body));
req.end();
});
team.html
<div ng-repeat="team in teamData">
<h2>{{team.name}}</h2>
....
</div>
My goal is to update the ng-repeat list just after PUT request is made (no page refresh). How can I achieve it?
Upvotes: 1
Views: 458
Reputation: 62
Assign it back to the model. For example if your ng-repeat was on $scope.item then:
return $http(req).then(function(res){
callback(res);
$scope.item = res
}, function(err){
callback(err);
});
Upvotes: 2