How to make a post request with angular 5

后端 未结 5 2104
面向向阳花
面向向阳花 2020-12-06 07:40

i want to make a post resquest using angular 5, but it gives me an error : here is the code :

service.ts

import { Injectable } from \'@angular/core\'         


        
5条回答
  •  一个人的身影
    2020-12-06 07:54

    try using this in your service.ts

    import {Headers} from 'angular2/http';
    var headers = new Headers();
    headers.append(headerName, value);
    
    addUser(user : User){
        return this.http.post(this._baseUrl + '/API/identity/user',user,{ headers: headers}).map((response: Response) =>{
        console.log (response.json());
        })
    }
    

    here you need to send user interface to HTTP post. and map your response.

    in ts file

    createUser(){
    
     this.dataService.addUser(this.user2).subscribe(data => {alert("Succesfully Added Product details")},Error => {alert("failed while adding product details")})
    }
    

提交回复
热议问题