Currently, I am working on retrieving JSON data which will be sent to my localhost through a POST method. The SpringBoot API controller will validate the JSON content before forwarding it to my localhost. My task is to intercept this JSON data when it is thrown and display it.
Although I have code that successfully requests data from the API (which is unnecessary in this case), I am struggling to implement the logic for the scenario mentioned above.
Component.ts:
constructor(private route: ActivatedRoute, private posting: MyDataService) {
console.log(window.location.href);
}
ngOnInit() {
this.posting.postMethod(formData)
.subscribe(
res => console.log(res),
err => alert("Pokemon failed to come out"),
)
}
Service.ts:
@Injectable()
export class MyDataService {
constructor(private http: Http) { }
postMethod(data:FormData): Observable<any> {
return this.http.post("http://ABCXYZ", data)
.map(res => res.json())
.catch(err=> Observable.throw(err))
}
}