I have been researching this topic further, but none of the solutions provided have helped me. I am attempting to make an http.get() request in Angular using a URL from Firebase: https://firestore.googleapis....
Despite successfully receiving JSON data through the URL, I have been unable to retrieve it in my code. Here is the approach I am currently trying:
import { Injectable } from '@angular/core';
// install rxjs first: npm install rxjs-compat --save
import { Observable } from 'rxjs/Observable';
import { BookModel } from '../../models/book/book.model';
import { Subject } from 'rxjs/Subject';
import { AngularFirestore } from '@angular/fire/firestore';
//import { AngularFirestore } from 'angularfire2/firestore';
// se non presente: npm install @angular/http@latest
import { Http } from '@http/http';
//import { HttpClient } from '@common/http';
import { map } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class CartService {
private emitAddToCart = new Subject<any>();
addEmitted$ = this.emitAddToCart.asObservable();
// http requests (https://firebase.google.com/docs/firestore/use-rest-api) example of httprequest
hardCodeUrl = 'https://firestore.googleapis.com/v1/projects/angularfirebasegb/databases/(default)/documents/cart?key=AIzaSyDNW48hAmvH8eAZpbeflRKb0khY5Blzsqg';
...
When calling service.httpCall() from another class, it returns "RISULTATO undefined". I attempted to call
return this.http.get(this.hardCodeUrl);
as follows:
service.httpCall().subscribe(data => {
responseFromBackEnd = data;
});
However, the response still remains undefined even after parsing it in the following way:
let jsonFromBackend = JSON.parse(responseFromBackEnd.text());
This results in an error due to the undefined value. Update: By implementing
return this.http.get(this.hardCodeUrl).subscribe(result => {
console.log("RISULTATO", result);
});
An object like the following is returned:
https://i.sstatic.net/PxRKV.png
and .text() yields an empty value