@almothafar/angular-signature-pad

中文文档
10.0.0发布于 2026/06/22MITTypeScriptES Module近 30 天下载 9.9万

Angular Component wrapper for szimek/signature_pad

原始使用文档
文档目录6 节
  1. Install
  2. Reference Implementation
  3. Usage example
  4. Migration from v9.x to v10.x
  5. Migration from v8.x to v9.x
  6. Migration from v6.x to v7.x

Angular Signature Pad

npm downloads npm version npm license GitHub issues Angular 22

Angular component for szimek/signature_pad.

✨ Now supports Angular 22! Built with standalone components and modern Angular signal APIs.

Install

npm install @almothafar/angular-signature-pad --save

Reference Implementation

Usage example

API is identical to szimek/signature_pad.

Options are as per szimek/signature_pad with the following additions:

  • canvasWidth: width of the canvas (px)
  • canvasHeight: height of the canvas (px)

The above options are provided to avoid accessing the DOM directly from your component to adjust the canvas size.

import { Component, viewChild } from '@angular/core';
import { SignaturePadComponent, NgSignaturePadOptions } from '@almothafar/angular-signature-pad';

@Component({
  selector: 'app-signature',
  standalone: true,
  imports: [SignaturePadComponent],
  template: `
    <signature-pad
      [options]="signaturePadOptions"
      (drawStart)="drawStart($event)"
      (drawEnd)="drawComplete($event)"
      (drawClear)="drawCleared()" />
  `
})
export class SignaturePadPage {

  public signaturePad = viewChild(SignaturePadComponent);

  public signaturePadOptions: NgSignaturePadOptions = { // passed through to szimek/signature_pad constructor
    minWidth: 5,
    canvasWidth: 500,
    canvasHeight: 300
  };

  ngAfterViewInit() {
    // this.signaturePad() is now available
    this.signaturePad().set('minWidth', 5); // set szimek/signature_pad options at runtime
    this.signaturePad().clear(); // invoke functions from szimek/signature_pad API
  }

  drawComplete(event: MouseEvent | Touch) {
    // will be notified of szimek/signature_pad's onEnd event
    console.log('Completed drawing', event);
    console.log(this.signaturePad().toDataURL());
  }

  drawStart(event: MouseEvent | Touch) {
    // will be notified of szimek/signature_pad's onBegin event
    console.log('Start drawing', event);
  }

  drawCleared() {
    // will be notified when clear() is called on the pad
    console.log('Pad cleared');
  }
}

Migration from v9.x to v10.x

Angular 22 support. The peer dependency range is unchanged (Angular >=20.0.0), so existing v9 consumers on Angular 20/21 keep working — no API changes. The library now ships from the Angular 22 toolchain and is fully zoneless-compatible. No code changes are required to upgrade.

Migration from v8.x to v9.x

Angular 19 dropped — minimum peer dependency is now Angular 20.0.0+.

drawEnd no longer emits null on clear. If you were checking for a null event in your drawEnd handler to detect when the pad was cleared, switch to the new dedicated drawClear output:

Before (v8.x):

<signature-pad (drawEnd)="onDrawEnd($event)"></signature-pad>
onDrawEnd(event: MouseEvent | Touch | null) {
  if (!event) {
    // pad was cleared
  }
}

After (v9.x):

<signature-pad (drawEnd)="onDrawEnd($event)" (drawClear)="onDrawCleared()" />
onDrawEnd(event: MouseEvent | Touch) { }

onDrawCleared() {
  // pad was cleared
}

options is now a model() signal, enabling optional two-way binding:

<!-- one-way (as before) -->
<signature-pad [options]="myOptions" />

<!-- two-way (new) -->
<signature-pad [(options)]="myOptions" />

Migration from v6.x to v7.x

In v7.x, the component is now standalone. Update your imports:

Before (v6.x):

import { AngularSignaturePadModule } from '@almothafar/angular-signature-pad';

@NgModule({
  imports: [AngularSignaturePadModule]
})

After (v7.x):

import { SignaturePadComponent } from '@almothafar/angular-signature-pad';

@Component({
  standalone: true,
  imports: [SignaturePadComponent]
})

Or if you're still using NgModule:

import { SignaturePadComponent } from '@almothafar/angular-signature-pad';

@NgModule({
  imports: [SignaturePadComponent]
})

版本与发布记录

@almothafar/angular-signature-pad 共发布 14 个版本,首次发布于 2020/12/23;过去 12 个月发布了 5 个版本。

版本发布日期距今
10.0.0latest2026/06/224 个月前
9.0.02026/04/156 个月前
8.0.02025/12/0111 个月前
7.0.02025/12/0111 个月前
6.0.12025/12/0111 个月前
6.0.02024/11/022 年前

关于 @almothafar/angular-signature-pad 的常见问题

@almothafar/angular-signature-pad 是什么?

Angular Component wrapper for szimek/signature_pad

如何安装 @almothafar/angular-signature-pad?

在项目目录运行 npm install @almothafar/angular-signature-pad,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@angular/common(>=20.0.0)、@angular/core(>=20.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@almothafar/angular-signature-pad 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@almothafar/angular-signature-pad 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@almothafar/angular-signature-pad 可以商用吗?

@almothafar/angular-signature-pad 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@almothafar/angular-signature-pad 的下载量有多少?

根据 npm 官方下载统计,@almothafar/angular-signature-pad 在 2026/10/06 – 2026/11/04 这 30 天内被下载 98,604 次,日均约 3,287 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@almothafar/angular-signature-pad 还在维护吗?

最新版本 10.0.0 发布于 2026/06/22(4 个月前);至今共发布 14 个版本,其中过去 12 个月发布了 5 个;首次发布于 2020/12/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。