gpt4 book ai didi

node.js - 更新用户详细信息 MEAN 堆栈

转载 作者:太空宇宙 更新时间:2023-11-04 01:50:15 25 4
gpt4 key购买 nike

我被困在更新用户个人资料上,我已经尝试了 Can't update user with PUT Request in Angular 2 上的解决方案但它似乎不起作用,也许它从我脸上开始,但我似乎无法弄清楚。

在我的 auth.service.ts 上我有这个

updateDetails(id) {
let headers = new Headers();
this.loadToken();
headers.append('Authorization', this.authToken);
headers.append('Content-Type', 'application/json');
return this.http.put('http://localhost:3000/api/admin/' + id, this.user { headers: headers })
.map(res => res.json());
}

然后在 client-edit.component.ts 上我有

updateUser(id) {
this.authService.updateDetails(id).subscribe(res => {
this.router.navigate(['/client-details', id]);
}, (err) => {
console.log(err);
})

user.js 文件有

router.put('/admin/:id', function(req, res, next) {
User.findByIdAndUpdate(req.params.id, req.body, function (err, post) {
if (err) return next(err);
res.json(post);
});
});

最后是 client-edit.component.html

<form (ngSubmit)="updateUser(user._id)"
......
...

任何人都可以看到我哪里出了问题,我在控制台中没有收到任何错误,我可以在终端中看到放置请求似乎正在通过,但是当我检查时它根本没有更新。

任何对此的见解我都会非常感激。

亲切的问候,- P

最佳答案

试试这个,

 return this.http.put('http://localhost:3000/api/admin/' + id, JSON.stringify(this.user), { headers: headers })

关于node.js - 更新用户详细信息 MEAN 堆栈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49992373/

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