В приведенном ниже коде я пытаюсь обновить пользовательские поля. Это моя editinfo.ts
страница
userSpecificData:any = {_id:'-',name: '-', email: '-', username: '-', password: '-', phone: '-',education:'-',location:'-',title:'-',company:'-'}
onEditFormSubmit(){
const user = {
_id:this.userSpecificData._id,
name: this.userSpecificData.name,
email: this.userSpecificData.email,
username: this.userSpecificData.username,
password: this.userSpecificData.password,
phone:this.userSpecificData.phone,
location:this.userSpecificData.location,
title:this.userSpecificData.title,
company:this.userSpecificData.company,
education:this.userSpecificData.education
}
if (this.EditPageUserForm.dirty && this.EditPageUserForm.valid) {
this.authService.updateUserData(user).subscribe(data => {
console.log(data);
if(data.success){
this.flashMessage.show('You are now successfully registered, redirecting to Login page..', {cssClass: 'alert-success', timeout: 4000});
//setTimeout(function(){
this.navCtrl.push(LoginPage);
// },4000)
console.log('sucess');
} else {
this.flashMessage.show('Something went wrong', {cssClass: 'alert-danger', timeout: 4000});
// this.router.navigate(['/register']);
console.log('faild');
return false;
}
});
}
}
Это мой auth.service.ts
файл
updateUserData(user) {
let headers = new Headers();
console.log(headers,user);
headers.append('Content-Type','application/json');
return this.http.put('http://localhost:3000/users/user/:id', user,{headers: headers})
.map(res => res.json());
}
Код ниже из файла маршрутов users.js
router.put('/user/:id', function(req, res){
User.findByIdAndUpdate({_id: req.params.id},
{
name: req.body.name,
email: req.body.email,
username: req.body.username,
phone:req.body.phone,
location:req.body.location,
title:req.body.title,
company:req.body.company,
education:req.body.education
}, function(err, docs){
if(err) res.json(err);
else
{
console.log(docs);
res.redirect('/user/'+req.params.id);
}
});
});
Я не получаю никакой ошибки в моем cmd, но из console.log(data);
из edit info.ts
Я получаю ошибку как
{message: «Ошибка приведения к ObjectId для значения« {_id: ': id'} »в пути
"_id" для модели "Пользователь" ", имя:" CastError ", stringValue:" "{_id:
': id'} "", вид: "ObjectId", значение: {…},…}