| 174 | const legacyErrors = signal<ValidationErrors | null>(null); |
| 175 | |
| 176 | @Component({ |
| 177 | selector: 'legacy-control-with-validators', |
| 178 | template: `<input [value]="value" (input)="onInput($event.target.value)" />`, |
| 179 | providers: [ |
| 180 | {provide: NG_VALUE_ACCESSOR, useExisting: LegacyControlWithValidators, multi: true}, |
| 181 | {provide: NG_VALIDATORS, useExisting: LegacyControlWithValidators, multi: true}, |
| 182 | ], |
| 183 | }) |
| 184 | class LegacyControlWithValidators implements ControlValueAccessor, Validator { |
| 185 | value = ''; |
| 186 | |
| 187 | private onChangeFn?: (value: string) => void; |
| 188 | |
| 189 | writeValue(newValue: string): void { |
| 190 | this.value = newValue; |
| 191 | } |
| 192 | |
| 193 | registerOnChange(fn: (value: string) => void): void { |
| 194 | this.onChangeFn = fn; |
| 195 | } |
| 196 | |
| 197 | registerOnTouched(fn: () => void): void {} |
| 198 | |
| 199 | validate(control: AbstractControl): ValidationErrors | null { |
| 200 | return legacyErrors(); |
| 201 | } |
| 202 | |
| 203 | onInput(newValue: string) { |
| 204 | this.value = newValue; |
| 205 | this.onChangeFn?.(newValue); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | @Component({ |
| 210 | imports: [LegacyControlWithValidators, FormField], |
nothing calls this directly
no test coverage detected