This project is about OTP UI. You can customize OTP length, form title and description.
- Angular CLI v13.0.0
- Node.js v16.16.0
- Project uses ngx-bootstrap v8.0.0, To add ngx-bootstrap :
ng add [email protected]
npm i
in root directoryng serve
for dev server (http://localhost:4200/
)
- Run
ng test
to execute the unit tests via Karma.
- Copy OTP module to your project
- Add OtpModule to your module
@NgModule({
...
imports: [
...
OtpModule,
...
],
...
})
- Implementation - 1 : Show using HTML template
// in html file:
...
<otp-component *ngIf="show" (onVerify)="verify($event)"></otp-component>
...
// in ts file:
...
show=true;
verify(otp:number){
console.log(otp)
}
...
- Implementation - 2 : Show using OtpService.
import { OtpService } from './otp/services/otp.service';
...
constructor(private otpService: OtpService) {
this.otpService.onVerify.subscribe((otp) => {
console.log(otp);
});
}
...
// Show the otp form
this.otpService.show({
formMessage: 'this is form message',
formTitle: 'First',
otpLength: 6,
});
// Manually hide the otp form
this.otpService.hide();
See appComponent for example.
Display OTP form compoent to UI with given params.
Params | Type | Default | Description |
---|---|---|---|
formTitle | string | OTP Verification | Display title of the form. |
formMessage | string | Please enter the OTP that we have sent you. | Display message in small font. for ex. (we have sent mail to [email protected]) |
otpLength | number | 4 | Length Of OTP |
To manually hide OTP component from UI, no params reqired.
You can subscribe to this Observable.
It will be called when user press verify button with OTP as a value.
Example:
this.otpService.onVerify.subscribe((otp) => {
console.log(otp);
});