>

CODEMASTERYLAB

IDE PLATFORM
CoursesCommunity BlogsKnowledge GraphQuizzesInterview Prep

Sign in to track progress & earn XP

Sign In Create Account
>
Code Mastery Lab

Code Mastery Lab

Sign In

HttpClient — Making Real API Calls the Angular Way

Question 1 / 1

0:00
Core
Medium

Your component calls this.productService.getProducts() and stores the result in products$. The template binds to it with async pipe AND you call .subscribe() in ngOnInit to log the results. How many HTTP requests fire?

typescript export class ProductListComponent implements OnInit { products$: Observable<Product[]>;

ngOnInit() { this.products$ = this.productService.getProducts(); this.products$.subscribe(p => console.log('Logging:', p)); // subscription 1 } }

html

<div *ngIf="products$ | async as products"> <!-- subscription 2 --> <div *ngFor="let p of products">{{ p.name }}</div> </div>