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.
model() defines a writable input and also creates a <name>Change output to support two-way binding for custom components.
Example checkbox-like component:
typescript
@Component({ template: `<button (click)="checked.update(v => !v)">{{ checked() }}</button>` })
export class ToggleButton {
checked = model(false)
}Use it for components that edit one value, such as checkboxes/date pickers; if a component only renders data, read-only input() is clearer.