File

src/app/core/http/question.service.ts

Index

Methods

Constructor

constructor(http: HttpClient)
Parameters :
Name Type Optional
http HttpClient No

Methods

getQuestion
getQuestion(id: number)

Builds an observable for making a GET request to get a question.

Parameters :
Name Type Optional Description
id number No

The question's id.

An Observable of the question.

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { tap } from 'rxjs/operators';
import { Question } from '../data/models/question.model';
import { Observable } from 'rxjs';
import { environment } from 'src/environments/environment';

@Injectable({
  providedIn: 'root',
})
export class QuestionService {
  constructor(private http: HttpClient) {}

  /**
   * Builds an observable for making a GET request to get a question.
   *
   * @param id The question's id.
   * @returns An Observable of the question.
   */
  getQuestion(id: number): Observable<Question> {
    const url = environment.baseUrl + 'questions/' + id;

    return this.http.get<Question>(url).pipe(tap(q => console.log(q)));
  }
}

result-matching ""

    No results matching ""