Senior
18 tháng 11, 2026

Tìm lỗi: Angular

Một đoạn mã. Tìm ra lỗi, hoặc chứng minh là không có lỗi nào.

typescript
1import { Directive, inject, DestroyRef } from '@angular/core';
2import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
3import { Observable } from 'rxjs';
4
5@Directive()
6export abstract class BaseListComponent<T> {
7  protected readonly destroyRef = inject(DestroyRef);
8
9  protected abstract load(): Observable<T[]>;
10
11  protected items: T[] = [];
12
13  protected refresh() {
14    this.load()
15      .pipe(takeUntilDestroyed(this.destroyRef))
16      .subscribe((data) => (this.items = data));
17  }
18}
19

Nhấp vào những dòng gây ra vấn đề.

Phán quyết của bạn

Một lần thử mỗi ngày. Đáp án hiện ra ngay sau đó.

Giữ chuỗi ngày của bạn

Tạo tài khoản để giữ chuỗi ngày và theo dõi tiến độ của bạn.

Tạo tài khoản