I am trying to do HTTP get/post request. Even with a fresh install of Angular 4 using the CLI, I am facing an unusual problem. When I send get request for first attempt then it gives undefined
on console.log()
, though from 2nd attempt data shows normally. Same result on Laravel as a server and even on JSON file. But while printing fetched data it prints but after few seconds. But it is OK though.
Same kind of problem arises on post request as well. Whenever form submits nothing happens on first attempt and shows some error on console.log()
that server is not connected (something like that), and on second attempt it just submits normally as it should be.
this.http.get(path).subscribe(data => this.response = data);
this.http.post(path, formData).subscribe(data => this.response = data);