Skip to content

Latest commit

 

History

History

angular-example

README.md

StaticForms Angular Example

A contact form built with Angular 22 that sends submissions to your inbox through StaticForms.dev. There's no backend to write or host.

Deploy with Vercel

📖 Step-by-step tutorial: Getting started with Static Forms on the StaticForms blog.

Features

  • Standalone components (zoneless)
  • Signals for form status
  • Built-in control flow (@if)
  • scripts/write-env.mjs injects the API key at build time
  • Loading, success and error states
  • Shared styling with every other example in this repo

Quick Start

# From the monorepo root
pnpm install
cp apps/angular-example/env.example apps/angular-example/.env
# Add your API key to the new file, then:
pnpm dev:angular

The app runs on http://localhost:3006.

Environment Variables

Variable Description
NG_APP_STATICFORMS_API_KEY Your StaticForms.dev API key. Get one free at staticforms.dev.

Locally, put it in .env. On Vercel, the deploy button asks for it; you can also add it later under Settings → Environment Variables.

The env file keeps your key out of git. Like the hidden apiKey field in a plain HTML form, the key is still visible in the browser once the site is deployed.

Deploy to Vercel

Click Deploy with Vercel above. Vercel copies this repository into your account, sets the project's Root Directory to apps/angular-example and asks for NG_APP_STATICFORMS_API_KEY.

vercel.json in this folder installs only this example's dependencies from the monorepo. Output: Static (dist/angular-example/browser).

To deploy manually, import the repository at vercel.com/new, set Root Directory to apps/angular-example, add the environment variable, and deploy.

Project Structure

Path Purpose
src/app/app.html Page layout
src/app/contact-form/contact-form.ts Contact form logic
src/app/contact-form/contact-form.html Contact form template
scripts/write-env.mjs Writes the API key to src/env.generated.ts
vercel.json Vercel deployment settings
env.example Environment variable template

How It Works

The form POSTs JSON to the StaticForms API:

POST https://api.staticforms.dev/submit
Content-Type: application/json

{
  "apiKey": "YOUR_API_KEY",
  "name": "Jane Doe",
  "email": "jane@example.com",
  "message": "Hello!",
  "replyTo": "@",
  "subject": "New Contact Form Submission"
}

"replyTo": "@" sets the reply-to address to the sender's email. The API responds with { "success": true }, or with { "success": false, "message": "..." } when something goes wrong.

Learn More

From the StaticForms blog:

Docs:

License

MIT