npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

ngx-otp-code

v0.0.8

Published

Customizable OTP input component for Angular with Web OTP support.

Downloads

38

Readme

ngx-otp-inputs

Angular OTP (One Time Password) input component with Web OTP support, reactive forms integration and flexible configuration.

npm version Downloads


✨ Major Features

✅ Customizable length (e.g. 4, 6, etc.)
✅ Numeric or alphanumeric codes
✅ Masked or plain text inputs
✅ Web OTP API integration (auto-read codes from SMS)
✅ Compatible with Reactive Forms (ControlValueAccessor)
✅ Easy error handling via outputs
✅ Standalone Angular Component
✅ Lightweight and dependency-free (except Angular itself)


🚀 Installation

Install the package via npm:

npm install --save ngx-otp-code

or with yarn:

yarn add ngx-otp-code

⚙️ Basic Usage

Import the Component

If you’re using Angular standalone components:

import { NgxOtpCodeComponent } from 'ngx-otp-code';

Or import the module in your NgModule:

import { NgxOtpModule } from 'ngx-otp-code';

@NgModule({
  imports: [NgxOtpInputsModule]
})
export class YourModule {}

✅ Example with Reactive Forms

// your.component.ts

import { Component } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';

@Component({
  selector: 'app-my-form',
  templateUrl: './my-form.component.html'
})
export class MyFormComponent {
  form: FormGroup;

  otpConfig = {
    length: 6,
    inputType: 'number',
    autoFocus: true,
    placeholder: '*',
    mask: false,
    useWebOtp: true
  };

  constructor(private fb: FormBuilder) {
    this.form = this.fb.group({
      otp: ['']
    });
  }

  submit() {
    console.log(this.form.value.otp);
  }

  handleOtpError(msg: string) {
    console.error(msg);
  }

  handleCodeFilled(code: string) {
    console.log('OTP complete:', code);
  }
}

Template

<form [formGroup]="form" (ngSubmit)="submit()">
  <ngx-otp-code
    formControlName="otp"
    [config]="otpConfig"
    (error)="handleOtpError($event)"
    (codeFilled)="handleCodeFilled($event)"
  ></ngx-otp-code>

  <button type="submit">Submit</button>
</form>

🔧 Configuration Options

Pass a single config object to customize behavior:

| Property | Type | Default | Description | | | ------------- | --------- | ---------- | ---------------------------------- | ---------- | | length | number | 6 | Number of OTP inputs | | | inputType | `'text' | 'number'` | 'text' | Input type | | placeholder | string | '' | Placeholder for each input box | | | autoFocus | boolean | true | Autofocus first input | | | isAlpha | boolean | false | Allow letters and numbers | | | mask | boolean | false | Mask input values (password style) | | | useWebOtp | boolean | false | Enable Web OTP API | |

📤 Outputs

(error)

Emits a string describing any error, e.g. invalid paste:

(error)="handleOtpError($event)"

(codeFilled)

Emits the complete OTP code as soon as all digits are filled:

(codeFilled)="handleCodeFilled($event)"

🔐 Web OTP API

This component supports the Web OTP API for automatically reading codes from SMS messages.

✅ Works only over HTTPS ✅ Not supported in all browsers

Enable it by setting:

[config]="{ useWebOtp: true }"

🎨 Custom Styling

ngx-otp-code is designed to be styled exclusively via CSS classes for full flexibility and theme compatibility. There are no inline styles in the component, giving you full control over its appearance.


Default Classes

By default, the component generates these classes:

  • .otp-container → wraps all input fields.
  • .otp-input → applied to every input field.

Custom Classes

You can provide your own classes via the config object:

  • containerClass → custom class for the container.
  • inputClass → custom class for all inputs.

Example:

<ngx-otp-code
  [config]="{
    length: 6,
    inputType: 'text',
    mask: false,
    placeholder: '*',
    inputClass: 'my-otp-input',
    containerClass: 'my-otp-container'
  }"
  [formControl]="otpControl">
</ngx-otp-inputs>

🎯 Styling Tips

✅ Define your styles globally or in SCSS files used in your Angular app. ✅ Use Angular’s ViewEncapsulation to control whether styles are global or component-scoped. ✅ Create themes or dark mode simply by switching classes.

🎯 Compatibility

Angular 17+

Modern browsers

📦 License

MIT © 2025


☕ Buy Me a Coffee

If you find this library helpful, you can support my work:

Buy Me A Coffee

👉 Buy Me a Coffee

🔎 Keywords

angular, otp, web-otp, otp-input, code-input, pin-input, one-time-password, ngx-otp-inputs, angular-library, two-factor-auth, authentication