https://angular.carbondesignsystem.com/?path=/story/components-checkbox—basic
组件及属性
Checkbox
- Input
- size: sm | md = md
- nested
- inline = false
- disabled = false
- skeleton = false
- hideLabel = false
- name
- id =
checkbox-${Checkbox.checkboxCount}
- required
- value
- aria-label,无障碍相关
- ariaLabel
- aria-labelledby
- indeterminate
- checked
- Output
- check
- change
- checkedChange
- indeterminateChange
- HostListener
- Input
https://hijiangtao.github.io/2020/01/30/Angular-ControlValueAccessor-Introduction-and-Example/
- https://angular.io/api/forms/ControlValueAccessor
ChangeDetectorRef
当使用 OnPush 策略时,如果输入属性没有变化,组件的变化检测将会被跳过,这种情况可以调用 markForCheck 方法手动检测。
ChangeDetectorRef 是组件变化检测器的应用,声明如下
ChangeDetectorRef 类的使用方式,后面可以单独写篇文章。现在我们只要知道它在这里用来触发手动检测。abstract class ChangeDetectorRef {
abstract markForCheck(): void
abstract detach(): void
abstract detectChanges(): void
abstract checkNoChanges(): void
abstract reattach(): void
}
参考
- https://www.cnblogs.com/lskzj/p/11143233.html
- https://www.digitalocean.com/community/tutorials/angular-change-detection-strategy
- https://angular.io/api/core/ChangeDetectorRef
- https://indepth.dev/posts/1053/everything-you-need-to-know-about-change-detection-in-angular
Code
https://github.com/IBM/carbon-components-angular/blob/34c320edea67d9012a6778e5f9fef633b782908a/src/checkbox/checkbox.component.ts感谢
朋友你好,如果你对我的文章感兴趣,欢迎关注我的 Github (https://github.com/llccing),或者掘金 (https://juejin.cn/user/3227821867281079),或者语雀 (https://www.yuque.com/uov16w),感谢你的支持!