Asynchronous operations can be tricky in programming. Check fifty fith question of full-stack dev quiz to see what you know about sending HTTP GET requests in Angular TS and reading the response.
Look at the below TypeScript code:
import { Injectable } from '@angular/core';
import {Observable} from "rxjs";
import {HttpClient} from "@angular/common/http";
@Injectable({
providedIn: 'root'
})
export class BlogsService {
constructor(private http: HttpClient) { }
public getUsefulBlogs(): XYZ {
return this.http.get<Blog[]>("/blogs/useful");
}
}
export interface Blog {
name: string,
url: string
}
What object type (marked as XYZ) is returned by getUsefulBlogs()
function? It basically returns the same as the get function of HttpClient
. Choose the best answer.
- Blog
- Blog[]
- HttpClient
- Event<Blog>
- Subscription<Blog[]>
For the correct answer scroll down
.
.
.
.
.
.
The correct answer is: e. If you would like to read more, check Mocking REST API in AngularTS article.