Mid-Level
August 19, 2026Spot the bug: Angular
One snippet. Find the bug, or prove there isn't one.
typescript
1import { Injectable, Component } from '@angular/core';
2import { BehaviorSubject } from 'rxjs';
3
4@Injectable({ providedIn: 'root' })
5export class CartService {
6 private itemsSubject = new BehaviorSubject<string[]>([]);
7 items$ = this.itemsSubject.asObservable();
8
9 add(item: string) {
10 this.itemsSubject.next([...this.itemsSubject.value, item]);
11 }
12}
13
14@Component({
15 selector: 'app-cart-badge',
16 template: `<span>{{ (items$ | async)?.length }}</span>`,
17 providers: [CartService],
18})
19export class CartBadgeComponent {
20 items$ = this.cart.items$;
21 constructor(private cart: CartService) {}
22}Click the lines that carry the problem.
Your verdict
One attempt per day. The answer shows up right after.
Keep your streak
Create an account to keep your streak and track your progress.