[英]ERROR in PUT request (Angular 4 w/ NodeJs API REST)
I'm trying to make a crud in angular 4 using an api rest wrote in nodejs. 我正在尝试使用在nodejs中编写的api rest使角度为4。
I was following this tutorial: https://youtu.be/3zpdnujI_B0?t=2239 我正在关注本教程: https : //youtu.be/3zpdnujI_B0?t=2239
But when the guy starts to make the PUT methot, doesn't worked for me... 但是当那个家伙开始使PUT变得炙手可热时,对我来说就不起作用了...
I'm searching the solution for about 2 days 我正在寻找解决方案大约2天
My PROJECT is here: https://stackblitz.com/github/Mauricio-vieira/newRepository 我的项目在这里: https : //stackblitz.com/github/Mauricio-vieira/newRepository
My API REST worte in NodeJs is here: https://github.com/Mauricio-vieira/apinode 我在NodeJs中的API REST代码在这里: https : //github.com/Mauricio-vieira/apinode
(it starts with: "node server.js"), (the mysql file is in the instruction to make the db/tables) (以“ node server.js”开头),(mysql文件位于制作数据库/表的指令中)
Glad if you could help me :) 很高兴能帮到我:)
I guess the issue lies here, you do not need to pass id for put, and your API does not take that as a parameter 我想问题出在这里,您不需要传递id来放置,并且您的API不会将其作为参数
let url = `${this.produtosUrl}/:10`;
change this to just 更改为
let url = `${this.produtosUrl}`;
and 和
updateProduto (produto: Produto): Observable<any> {
return this.http.put(this.produtosUrl, produto, httpOptions).pipe(
tap(_ => this.log(`updated produto id=${produto.id}`)),
catchError(this.handleError<any>('updateProduto'))
);
}
also on your node server, 也在您的节点服务器上,
Try using CORS module in Node.js server: 尝试在Node.js服务器中使用CORS模块:
var cors = require('cors')
app.use(cors());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.