Angular's missing trim input functionality (equivalent of AngularJS ng-trim
)
Caveats:
matInput
directive uses a value accessor).To install this library, run:
$ npm install ng-trim-value-accessor --save
In your Angular AppModule
:
import { NgModule } from '@angular/core';
import { TrimValueAccessorModule } from 'ng-trim-value-accessor';
@NgModule({
imports: [
TrimValueAccessorModule
]
})
export class AppModule { }
By default, it ignores all readonly
and input[type="password]
fields. For example the following field remains untouched:
<input class="form-control" name="startDate" [(ngModel)]="model.startDate" ngbDatepicker readonly>
However if you want to explicitly opt-out, give a field ng-trim-ignore
css class:
<input type="text" class="form-control ng-trim-ignore" name="firstName" [(ngModel)]="model.firstName">