Mauricio Renan
Mauricio Renan

Reputation: 55

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.

I was following this tutorial: https://youtu.be/3zpdnujI_B0?t=2239

But when the guy starts to make the PUT methot, doesn't worked for me...

I'm searching the solution for about 2 days

My PROJECT is here: https://stackblitz.com/github/Mauricio-vieira/newRepository

My API REST worte in NodeJs is here: https://github.com/Mauricio-vieira/apinode

(it starts with: "node server.js"), (the mysql file is in the instruction to make the db/tables)

Glad if you could help me :)

Upvotes: 1

Views: 178

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222652

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

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:

var cors = require('cors')

app.use(cors());

Upvotes: 2

Related Questions