MCPcopy
hub / github.com/angular/angular / CustomControl

Class CustomControl

packages/forms/signals/test/web/interop.spec.ts:67–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65 });
66
67 @Component({
68 selector: 'custom-control',
69 template: `
70 <input
71 [value]="value"
72 [disabled]="disabled"
73 (blur)="onBlur()"
74 (input)="onInput($event.target.value)"
75 />
76 `,
77 providers: [{provide: NG_VALUE_ACCESSOR, useExisting: CustomControl, multi: true}],
78 changeDetection: ChangeDetectionStrategy.Eager,
79 })
80 class CustomControl implements ControlValueAccessor {
81 value = '';
82 writeCount = 0;
83 disabled = false;
84
85 private onChangeFn?: (value: string) => void;
86 private onTouchedFn?: () => void;
87
88 writeValue(newValue: string): void {
89 this.value = newValue;
90 this.writeCount++;
91 }
92
93 registerOnChange(fn: (value: string) => void): void {
94 this.onChangeFn = fn;
95 }
96
97 registerOnTouched(fn: () => void): void {
98 this.onTouchedFn = fn;
99 }
100
101 setDisabledState(disabled: boolean): void {
102 this.disabled = disabled;
103 }
104
105 onBlur() {
106 this.onTouchedFn?.();
107 }
108
109 onInput(newValue: string) {
110 this.value = newValue;
111 this.onChangeFn?.(newValue);
112 }
113 }
114
115 @Directive({
116 selector: '[cvaDir]',

Callers

nothing calls this directly

Calls 2

ComponentInterface · 0.90
signalFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…