๐Ÿ” OTP Angular

August 6, 2025 ยท View on GitHub

Otp Angular is a lightweight, highly customizable, and dependency-free OTP (One-Time Password) input component built for Angular 20+ applications. It offers seamless integration, flexible configuration, and a polished user experience for OTP or verification inputs. The component now also includes a built-in resend option, making it easy to handle OTP resubmission flows directly within the UI.

โœ… Supports Angular 20+
๐Ÿ”ง Fully customizable
๐ŸŽฏ Keyboard navigation support
๐Ÿงช Easily testable & maintainable
๐Ÿ’ก Auto-focus, password-style, number-only, and more


OTP Input Demo

Demo

๐Ÿ“ฆ Installation

npm install otp-angular

๐Ÿš€ Latest changes in 1.0.4

  • Update Readme Readme file updated

๐Ÿš€ Latest changes in 1.0.3

  • Support ReactiveFormsModule & FormsModule formControl and ngModel are supported
  • Support types on Config types will be available
  • Fixed Paste Event types will be available

๐Ÿš€ latest Changes in 1.0.1

  • Emits null instead of an empty string if no value is supplied
  • Resend Option added if you add resend as option then it will open

Usage

For Component

import { OtpAngular, OtpAngularType } from 'otp-angular';

@Component({
  imports: [...others, OtpAngular, OtpAngularType]
})

export class <ComponentName> {
  protected config = signal<OtpAngularType>({ length: 4 });
}

For Template

@let _config = config();
<!-- With Event Binding -->
<otp-angular [config]="_config" (onInputChange)="onInputChange($event)"  (onResendAvailable)="resend($event)" />

<!-- Using Reactive FormControl -->
<otp-angular [config]="_config" formControlName="otp" />

<!-- Using Forms Module -->
<otp-angular [config]="_config" [(ngModel)]="otp" />


โš™๏ธ Inputs/Outputs

OptionTyperequiredDescriptionDefault
disabledbooleanNoDisables otp when set to truefalse
onInputChangeOutputNoEmits the OTP value on change, it's return string, number or nullโ€”
onResendAvailableOutputNoEmits when you click resend option, as a boolean(true)โ€”
setValuefunctionNoSet the otp valueโ€”
resetfunctionNoReset the Resendโ€”
configobjectYesConfigure based on option. (see Config Options below){ length: 4 }

โš™๏ธ Config Options

OptionTyperequiredDescriptionDefault
lengthnumberYesNumber of OTP digits4
numbersOnlybooleanNoAllow only numeric inputfalse
autoFocusbooleanNoAuto-focus first inputfalse
isPasswordbooleanNoMask input charactersfalse
showErrorbooleanNoShow red border on errorfalse
showCapsbooleanNoTransform to Capital lettersfalse
containerClassstring or string[]NoCustom CSS class for containerโ€”
containerStylesobjectNoInline styles for container{}
inputClassstring or string[]NoCustom class for input boxesโ€”
inputStylesobject or object[]NoInline styles for input fields{}
placeholderstringNoPlaceholder for each input box''
separatorstringNoOptional separator character''
resendnumberNoEnable the Resend option0
resendLabelstringNoLabel for ResendRESEND VERIFICATION CODE
resendContainerClassstringNoCustom class for resend container''
resendLabelClassstringNoOptional class for resend Label''
resendTimerClassstringNoOptional class for resend timer''

๐Ÿ“˜ Option Descriptions

  • length: Sets how many input boxes are shown (e.g., 6 for a 6-digit OTP).
  • numbersOnly: If true, only numeric input is allowed in each box.
  • autoFocus: Automatically focuses the first input box on load.
  • isPassword: Hides characters behind dots, like a password field.
  • showError: Enables error styling (e.g., red border).
  • showCaps: Transform to Capital letters .
  • **containerClass / inputClass / resendContainerClass / resendLabelClass / resendTimerClass **: Lets you add your own CSS classes for styling.
  • containerStyles / inputStyles: Set inline styles directly from your component.
  • placeholder: The character shown in empty input boxes (like * or _).
  • separator: Visual separator between input boxes (like - or :).
  • resend: Sets the value to show the Resend option, value will be in seconds (like 60).
  • resendLabel: To change the label for resend (e.g., Resend Code).

๐Ÿงฉ Other Features

Use @ViewChild to get a reference to the component

@ViewChild(OtpAngular, { static: false }) otpRef!: OtpAngular;

๐Ÿ”’ Disabling Inputs

You can disable all input fields using the disabled input or programmatically:

this.otpRef.disabled.set(true);

๐Ÿ” Updating OTP Value

this.otpRef.setValue('1234');

๐Ÿ” Reset the timer of resend

this.otpRef.reset();

๐Ÿ“„ License

License: MIT npm npm GitHub issues GitHub stars GitHub license