1

I use http.delete for remove my data.

This code in my service [MyService]:

deleteData(id){
  let headers = new Headers(),authtoken = localStorage.getItem('token');
     headers.append("Authorization", 'Bearer' + authtoken);
     headers.append('X-Requested-With', 'XMLHttpRequest')
     headers.append('Content-Type', 'application/json;')

    return this.http.delete('http://link/'+id, { headers: headers })
                  .map((resp:Response)=>resp.json())
                  .catch((error:any) =>{return Observable.throw(error);}); 
 } 

This code in my component:

private delete(id):void{
         console.log(id); //show`s id
         this.myService.deleteData(id)
         .subscribe((data) => {console.log(data)});
}

Show`s error "caused by: A network error occurred". My mistake was elsewhere. It is work.

1 Answer 1

1

There is nothing wrong in your code what i can see and you are not getting any error from server either. Try to call the same end point from postman and match the headers and check your Internet connection.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, you are right. My mistake was elsewhere. It is work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.