so the project is so simple. the user inputs some infos about a book and click submit to save the infos in a database (Mongodb) i'm using MEAN STACK and i'm a noobie (obviously). nothing happens when i submit not even an error.
backend code :
//POST ONE BOOK
booksRoute.route('/post').post((req,res,next)=>{
var x = {
name : req.params.name,
genre : req.params.genre,
author : req.params.author,
rating : req.params.rating,
price : req.params.price
}
console.log(x) ;
BookModel(x).save((err,data)=>{
if (err){console.log(err);}
else res.send(data) ;
}) ;
})
add book component html :
<ul>
<form #f="ngForm" (ngSubmit)="onSubmit(f)">
<li>
<label>book's name *</label>
<input name="name" type="text" ngModel>
</li>
<li>
<label>book's genre *</label>
<input name="genre" type="text" ngModel>
</li>
<li>
<label>book's author *</label>
<input name="author" type="text" ngModel>
</li>
<li>
<label>rating *</label>
<input name="rating" type="number" [max]="10" min="0" ngModel>
</li>
<li>
<label>price *</label>
<input name="price" type="number" ngModel>
<input class="btn btn-primary" type="submit"/>
</li>
</form>
</ul>
angular service
postBook(data){
console.log(data) ;
return this.http.post(this.backendUrl+'/post',data) ;
}
in addBook component ts
onSubmit(f){
//console.log(f.value) ;
this.apiService.postBook(f.value) ;
}
Note : i can get data from the database, i can find a book by it's name but i can't post