NOTE: The issue lies in the ionViewDidLoad() function not being executed, as the http.get method does return an observable. I am attempting to receive the observable when making a request to later retrieve its json response. However, I am not encountering any errors and nothing is appearing in the browser's console either. It is perplexing why there is no output.
I have experimented with various URLs and thoroughly checked the imports. console.log doesn't show the data home.page.ts
import { ServicioService } from '../servicio.service';
import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http';
...
ionViewDidLoad(){
const hola = this.servicio.goWiki(this.userInput).
subscribe((response) => {
console.log(response);
});
}
servicio.service.ts
import { Injectable } from '@angular/core';
import { map } from 'rxjs/operators';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable()
export class ServicioService {
constructor(public http: HttpClient) {
console.log('goin!');
}
goWiki(userInput): Observable<any>{
return this.http.get('https://www.reddit.com/r/gifs/top/.json?limit=105sort=hot');
}
app.module.ts
import { ServicioService } from './servicio.service';
import { HttpClientModule } from '@angular/common/http';
imports: [HttpClientModule, BrowserModule, IonicModule.forRoot(), AppRoutingModule, ComponentesModule],
providers: [
ServicioService,...
I'm hopeful that by receiving an observable, I will be able to read and extract specific information from it.