The directive trims whitespaces from the end of an input text value.
- Install
ng2-trim-directive
.
npm i ng2-trim-directive
- Import
InputTrimModule
to your Angular module.
import { InputTrimModule } from 'ng2-trim-directive';
@NgModule({
imports: [
...
InputTrimModule,
...
],
...
- Add the "trim" attribute to a text input element.
<input type="text" trim />
or with an option: trim value only on the blur event.
<input type="text" trim="blur" />
Good luck.