gpt4 book ai didi

javascript - 如何在 http 请求后更新 ng-repeat 列表

转载 作者:行者123 更新时间:2023-11-30 16:02:12 24 4
gpt4 key购买 nike

在发出 PUT 请求后,我无法更新我的 ng-repeat 列表。服务很好。

Controller .js

teamData.updateTeam(team.id, teamObj, function(res) {
console.log('Success');
});

服务.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);
});
};

团队路线.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();
});

团队.html

<div ng-repeat="team in teamData">
<h2>{{team.name}}</h2>
....
</div>

我的目标是在发出 PUT 请求后立即更新 ng-repeat 列表(不刷新页面)。我怎样才能实现它?

最佳答案

将其分配回模型。例如,如果你的 ng-repeat 在 $scope.item 上,那么:

 return $http(req).then(function(res){
callback(res);
$scope.item = res
}, function(err){
callback(err);
});

关于javascript - 如何在 http 请求后更新 ng-repeat 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37555241/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com