1
サービスを使用して更新を試みています。サービスと同じリンクを使って郵便配達員を使用すると、更新プログラムは正常に動作します。ここで平均更新がサービスから機能していない、郵便配達員からのみ
は私のコードは次のとおりです。
myservice.service.ts:ルート/ users.js内部
updateUser(userid){
let headers = new Headers();
headers.append('Content-Type','application/json');
console.log('http://localhost:3000/users/update/'+ userid);
return this.http.put('http://localhost:3000/users/update/'+ userid,
{headers: headers}).map(res => res.json());
}
router.put('/update/:id', (req, res) => {
User.findByIdAndUpdate(req.params.id, {
$set: {
participates: true}
},
{
new: true
},
function(err, updatedUser){
if(err){
res.send("Error updating user");
} else{
res.json(updatedUser);
}
}
);
});
私はエラーを取得しないが、それはしていませんrouter.putに入るようです。 私は何が欠けていますか?
CORSヘッダーがありますか? – Claies
[CORSを許可する方法]の複製がありますか(https://stackoverflow.com/questions/7067966/how-to-allow-cors) – georgeawg
私は '@ angular/http'からimport {Http、Headers}を使用します。私はconst cors = require( 'cors'); app.use(cors());を使用します。私のindex.jsファイルの中 – Ivett