Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
217 views
in Technique[技术] by (71.8m points)

Angular 2 http.post() is not sending the request

When I make a post request the angular 2 http is not sending this request

this.http.post(this.adminUsersControllerRoute, JSON.stringify(user), this.getRequestOptions())

the http post is not sent to the server but if I make the request like this

this.http.post(this.adminUsersControllerRoute, JSON.stringify(user), this.getRequestOptions()).subscribe(r=>{});

Is this intended and if it is can someone explain me why ? Or it is a bug ?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Since the post method of the Http class returns an observable you need to subscribe it to execute its initialization processing. Observables are lazy.

You should have a look at this video for more details:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...