---
title: Angular SDK
description: "CaptchaLa Angular component: installation, inputs, outputs, injectCaptchala(), and verification flow."
---
# Angular SDK
Official Angular component for CaptchaLa CAPTCHA — published as [`@captcha-la/angular`](https://www.npmjs.com/package/@captcha-la/angular). Current version: **1.0.1**.
- Standalone component, no NgModule needed
- `injectCaptchala()` for verifying on your own button (bind mode), with signals
- Works with Angular 16 and later, zone.js or zoneless, and server-side rendering
- Loads the web SDK from our CDN at runtime
## Install
```bash
npm install @captcha-la/angular
# or
yarn add @captcha-la/angular
# or
pnpm add @captcha-la/angular
```
## Quick start
### Component
```ts
import { Component } from '@angular/core'
import { CaptchalaComponent, type CaptchalaResult } from '@captcha-la/angular'
@Component({
selector: 'app-login',
standalone: true,
imports: [CaptchalaComponent],
template: `
`
})
export class LoginComponent {
onSuccess(result: CaptchalaResult) {
// Send result.token to your server for validation.
console.log('pass_token:', result.token)
}
onError(err: unknown) {
console.error(err)
}
}
```
With NgModules, add `CaptchalaComponent` to the module's `imports`.
### `injectCaptchala()`
```ts
import { Component } from '@angular/core'
import { injectCaptchala } from '@captcha-la/angular'
@Component({
selector: 'app-login-form',
standalone: true,
template: `
`
})
export class LoginFormComponent {
// Destroyed automatically together with the component
readonly captcha = injectCaptchala({
appKey: 'your-app-key',
product: 'bind',
action: 'login'
})
async onSubmit(e: Event) {
e.preventDefault()
try {
const result = await this.captcha.verify()
// result.token → submit with the form
} catch (err) {
console.error('verification failed:', err)
}
}
}
```
## Inputs
| Input | Type | Default | Description |
|-------|------|---------|-------------|
| `appKey` | `string` | *required* | CaptchaLa application key |
| `serverToken` | `string` | - | One-time, server-issued challenge token. Required when the app has `server_token_required=true`. See [`serverToken` mode](#server-token) |
| `product` | `'popup' \| 'float' \| 'embed' \| 'bind'` | `'popup'` | Display mode |
| `action` | `string` | `'default'` | Action identifier (e.g. `login`, `register`, `checkout`) |
| `lang` | `string` | browser language | Language code (`zh-CN`, `en`, `ja`, …); unset = the browser language. Changing it switches the language in place |
| `theme` | `string \| object` | follows the system | Preset string or `{ custom: { brightness: 'light' \| 'dark' \| 'system', ... } }` (see [Web SDK options](../web-sdk#common-options)) |
| `bindTo` | `string \| HTMLElement` | - | Element or selector to bind to (only for `product="bind"`) |
| `onServerTokenExpired` | `() => Promise \| string \| null` | - | Called when `serverToken` is rejected; return a new token to retry once, or `null` to report the error |
Changing `appKey`, `product`, `action`, `bindTo`, `serverToken` or `theme` rebuilds the widget.
## Outputs
| Output | Payload | Description |
|--------|---------|-------------|
| `success` | `CaptchalaResult` (`{ token, type, action }`) | Verification succeeded |
| `error` | `error` | Loading or verification failed |
| `close` | - | CAPTCHA closed |
| `expired` | - | The pass token expired before it was used (once); with a listener, emitted instead of `error`; the widget shows the expiry. See [Token expiry](#token-expiry) |
| `ready` | - | CAPTCHA ready |
## Methods (via template reference or `viewChild`)
```ts
@Component({
standalone: true,
imports: [CaptchalaComponent],
template: `
`
})
export class AppComponent {}
```
| Method | Description |
|--------|-------------|
| `verify()` | Trigger verification |
| `reset()` | Reset CAPTCHA state |
| `destroy()` | Destroy the instance |
| `bind(selector)` | Bind to element (for `bind` mode). Named `bind` because `bindTo` is the input |
| `setLang(lang)` | Switch language in place |
| `getInstance()` | The underlying web SDK instance |
## `injectCaptchala()` / `CaptchalaService`
```ts
const {
ready, // Signal: the SDK is loaded and ready
loading, // Signal: the SDK is loading
error, // Signal: loading or configuration error
verify, // () => Promise: start a verification
reset, // () => void
bindTo, // (selector) => void
appendTo, // (selector) => void
setLang, // (lang) => void
destroy, // () => void (done for you by injectCaptchala)
} = injectCaptchala(options)
```
`injectCaptchala()` must run in an injection context (a constructor or field
initializer) and is destroyed with the component or service that created it.
Elsewhere, use `inject(CaptchalaService).create(options)` and call `destroy()`
yourself. `CaptchalaService.load()` preloads the SDK.
## Token expiry {#token-expiry}
If the pass token runs out before the form uses it, the widget shows that the
verification expired (in `bind` mode nothing is shown, since the button is
yours) and `expired` fires once, instead of `error`. Start a new verification
with `reset()` then `verify()`, or show your own prompt.
```ts
@Component({
standalone: true,
imports: [CaptchalaComponent],
template: `
@if (expired()) {
}
`
})
export class FormComponent {
token = signal('')
expired = signal(false)
}
```
Without an `(expired)` listener, `error` fires once (class `expired`).
`expired` never fires for offline or degraded tokens. `injectCaptchala({ onExpired })`
works the same way.
## Server-side rendering
The component renders nothing on the server and loads the SDK only in the
browser, after the view is created. `injectCaptchala()` stays idle on the server
(`ready()` is `false`, `verify()` rejects). No extra configuration is needed for
Angular SSR or prerendering.
## Production: `serverToken` mode {#server-token}
For high-value flows (login, register, payment) we recommend the **server-issued
token flow**. Your backend mints a one-time `server_token` (5-minute TTL) via
`POST /v1/server/challenge/issue` and hands it to the browser:
```ts
import { Component, inject, signal } from '@angular/core'
import { HttpClient } from '@angular/common/http'
import { CaptchalaComponent } from '@captcha-la/angular'
@Component({
selector: 'app-login-page',
standalone: true,
imports: [CaptchalaComponent],
template: `
@if (serverToken()) {
} @else {
Loading…
}
`
})
export class LoginPageComponent {
serverToken = signal(undefined)
constructor() {
inject(HttpClient)
.get<{ server_token: string }>('/api/captcha-token') // your own backend
.subscribe((d) => this.serverToken.set(d.server_token))
}
onSuccess(passToken: string) {
console.log('pass_token:', passToken)
}
}
```
The `@if` block syntax needs Angular 17; on Angular 16 use `*ngIf`.
- Never embed the app secret in browser code.
- Each `server_token` can be used exactly once. Fetch a new one before every widget mount.
- Apps with `server_token_required=false` can still use the public `appKey`-only flow.
With a Node.js backend, the [Node.js SDK](./server-node) issues the token
(`issueServerToken`). See [API Reference](/api-reference) for the full backend contract.
## Server-side validation
Send the token from `success` to your backend and validate it there. With the
[Node.js SDK](./server-node):
```ts
import { CaptchaLaClient } from '@captcha-la/node'
const captchala = new CaptchaLaClient() // CAPTCHALA_APP_KEY / CAPTCHALA_APP_SECRET
const result = await captchala.validate(token, { clientIp: req.ip })
if (result.valid) {
// Token is valid, proceed with the request
}
```
Or call the API directly:
```js
const response = await fetch('https://verify.captcha.la/v1/validate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-App-Key': process.env.CAPTCHALA_APP_KEY,
'X-App-Secret': process.env.CAPTCHALA_APP_SECRET
},
// client_ip is optional but recommended
body: JSON.stringify({ pass_token: token, client_ip: req.ip })
})
const result = await response.json()
if (result.code === 0 && result.data.valid === true) {
// Token is valid, proceed with the request
}
```
## TypeScript
```ts
import {
CaptchalaComponent,
CaptchalaService,
injectCaptchala,
type CaptchalaResult,
type CaptchalaHandle,
type CaptchalaHandleOptions
} from '@captcha-la/angular'
```
## Versions
- **1.0.1** (2026-11-27): README in Japanese, Korean, Spanish, Portuguese (BR) and German; no code changes.
- **1.0.0**: first public release.
## Links
- [npm](https://www.npmjs.com/package/@captcha-la/angular) · [GitHub](https://github.com/Captcha-La/angular)
- [Web SDK overview](/web-sdk) · [API Reference](/api-reference)