The directive trims whitespaces from the end of an input text value.
Play with the directive here https://anein.github.io/angular2-trim-directive/.
- Install
ng2-trim-directive.
npm i ng2-trim-directiveor using Yarn
yarn add ng2-trim-directive- Import
InputTrimModuleto your Angular module.
import { InputTrimModule } from 'ng2-trim-directive';
@NgModule({
imports: [
...
InputTrimModule,
...
],
...- Add the "trim" attribute to a text input or textarea element.
<input type="text" trim />
<textarea ... trim ></textarea>or with an option: trim value only on the blur event.
<input type="text" trim="blur" />
<textarea ... trim="blur" ></textarea>note: if you use the directive with <textarea> without setting the blur event, it will behave like the text input element.
Good luck.