MCPcopy Create free account
hub / github.com/angular/angular / CustomControl

Class CustomControl

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

ComponentInterface · 0.90
signalFunction · 0.90

Tested by

no test coverage detected