Trung BìnhAngular iconAngular

Model input `model()` dùng khi nào?

model() định nghĩa input có thể ghi, đồng thời tạo output <name>Change để hỗ trợ two-way binding cho custom component.

Ví dụ checkbox tự emit thay đổi:

typescript
@Component({ template: `<button (click)="checked.update(v => !v)">{{ checked() }}</button>` })
export class ToggleButton {
  checked = model(false)
}

Dùng cho component chỉnh sửa một giá trị như checkbox/date picker; nếu component chỉ render dữ liệu, dùng input() read-only rõ hơn.

Xem toàn bộ Angular cùng filter theo level & chủ đề con.

Mở danh sách Angular