MCPcopy Index your code
hub / github.com/angular/angular / TestNumberInput

Class TestNumberInput

packages/forms/signals/test/node/parse_errors.spec.ts:382–413  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

380});
381
382@Component({
383 selector: 'test-number-input',
384 template: `
385 <input type="text" [value]="rawValue()" (input)="rawValue.set($event.target.value)" />
386 @for (e of errors(); track $index) {
387 <p class="error">{{ e.message }}</p>
388 }
389 `,
390})
391class TestNumberInput implements FormValueControl<number | null> {
392 readonly value = model.required<number | null>();
393 readonly errors = input<readonly ValidationError[]>([]);
394 readonly parseMax = input<number | undefined>(undefined);
395
396 protected readonly rawValue = transformedValue(this.value, {
397 parse: (rawValue) => {
398 if (rawValue === '') return {value: null};
399 const value = Number(rawValue);
400 if (Number.isNaN(value)) {
401 return {error: {kind: 'parse', message: `${rawValue} is not numeric`}};
402 }
403 if (this.parseMax() != null && value > this.parseMax()!) {
404 return {value, error: [maxError(this.parseMax()!)]};
405 }
406 return {value};
407 },
408 format: (value) => {
409 if (value === null || Number.isNaN(value)) return '';
410 return value.toString();
411 },
412 });
413}
414
415async function act<T>(fn: () => T): Promise<T> {
416 const result = fn();

Callers

nothing calls this directly

Calls 6

ComponentInterface · 0.90
inputFunction · 0.85
transformedValueFunction · 0.85
maxErrorFunction · 0.85
toStringMethod · 0.65
requiredMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…