@baijudodhia/ng-forms v0.0.4
ng-forms
A fully customizable, one-time password input component for the web built with Angular.
Demo
Edit on Stackbliz
Installation
npm install --save ng-forms
Usage
Add NgFormsModule to imports app.module.ts
something like
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { NgFormsModule } from 'ng-forms';
@NgModule({
declarations: [AppComponent],
imports: [ BrowserModule,
NgFormsModule],
bootstrap: [AppComponent]
})
Add component to your page:
<ng-forms (onInputChange)="onOtpChange($event)" [config]="{length:5}"></ng-forms>
API
Config options
Updating component value using setValue method
Component value can be updated using setValue
method of the component example:-
<ng-forms #ngOtpInput ></ng-forms> //add hash to ng-forms component
then in your component reference using @ViewChild and call setValue
method when you want to set the value of component like
//Get reference using ViewChild and the specified hash
@ViewChild('ngOtpInput') ngOtpInputRef:any;
yourMethod(){
this.ngOtpInputRef.setValue(yourValue);
//yourvalue can be any string or number
}
Disable inputs
Inputs can be disabled by getting the otp form instance of the component and calling disable method
1.Get the component ref in the same way as done in SetValue method above 2.Call disable method of otpForm as follow
this.ngOtpInputRef.otpForm.disable();
License
Contributing
Add a star to show your support and feel free to open issues and pull requests!
3 years ago