UNPKG

@ionic/angular

Version:

Angular specific wrappers for @ionic/core

55 lines 2.87 kB
import { Directive, HostListener } from '@angular/core'; import { NG_VALUE_ACCESSOR } from '@angular/forms'; import { ValueAccessor } from '@ionic/angular/common'; import * as i0 from "@angular/core"; export class NumericValueAccessorDirective extends ValueAccessor { el; constructor(injector, el) { super(injector, el); this.el = el; } // Bind `$event` and cast `.target` in the body rather than `['$event.target']`: // this directive's multi-element selector makes Angular 22's stricter host-binding // type checking infer `$event` as the DOM `Event` (target: `EventTarget | null`), // not the concrete element. The single-element standalone CVAs keep `['$event.target']`. handleInputEvent(ev) { const el = ev.target; this.handleValueChange(el, el.value); } registerOnChange(fn) { if (this.el.nativeElement.tagName === 'ION-INPUT' || this.el.nativeElement.tagName === 'ION-INPUT-OTP') { super.registerOnChange((value) => { fn(value === '' ? null : parseFloat(value)); }); } else { super.registerOnChange(fn); } } /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.0", ngImport: i0, type: NumericValueAccessorDirective, deps: [{ token: i0.Injector }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive }); /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.0.0", type: NumericValueAccessorDirective, isStandalone: false, selector: "ion-input[type=number],ion-input-otp:not([type=text]),ion-range", host: { listeners: { "ionInput": "handleInputEvent($event)" } }, providers: [ { provide: NG_VALUE_ACCESSOR, useExisting: NumericValueAccessorDirective, multi: true, }, ], usesInheritance: true, ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.0", ngImport: i0, type: NumericValueAccessorDirective, decorators: [{ type: Directive, args: [{ standalone: false, selector: 'ion-input[type=number],ion-input-otp:not([type=text]),ion-range', providers: [ { provide: NG_VALUE_ACCESSOR, useExisting: NumericValueAccessorDirective, multi: true, }, ], }] }], ctorParameters: () => [{ type: i0.Injector }, { type: i0.ElementRef }], propDecorators: { handleInputEvent: [{ type: HostListener, args: ['ionInput', ['$event']] }] } }); //# sourceMappingURL=numeric-value-accessor.js.map