Skip to main content
This guide walks you through adding CometChat to an Angular app. By the end you’ll have a working chat UI.

Prerequisites

You need three things from the CometChat Dashboard: You also need:
  • Node.js 20.19+, 22.12+ or 24+ (what Angular 21 requires) and npm installed
  • Angular 17–21. The UI Kit declares @angular/core >=17.0.0 <22.0.0, so Angular 22 — what an unversioned ng new / @angular/cli@latest now creates — fails npm install with ERESOLVE
Auth Key is for development only. In production, generate Auth Tokens server-side via the REST API and use loginWithAuthToken(). Never ship Auth Keys in client code.

Step 1 — Create an Angular Project

This creates a new Angular 21 project with CSS styling and no server-side rendering. CometChat UIKit components require a browser environment. Pin the CLI major (@21) — the latest CLI scaffolds Angular 22, which the UI Kit does not support yet. For an existing app, check the major with npx ng version.

Step 2 — Install the UI Kit

@cometchat/chat-sdk-javascript, @cometchat/cards-angular and dompurify are required peer dependencies of the UI Kit. Install them explicitly as shown — yarn and older npm versions don’t add peer dependencies for you. Don’t use --legacy-peer-deps: an ERESOLVE here almost always means the Angular major is outside 17–21. If you want voice/video calling, also install:

Step 3 — Initialize CometChat

Initialize the UI Kit in main.ts before bootstrapping the Angular app. This uses the static CometChatUIKit.init() method — the dual-API pattern lets you call it outside Angular’s dependency injection context. New Angular projects don’t include an environments folder: create src/environments/environment.ts with your credentials.
src/environments/environment.ts
src/main.ts
init() must resolve before you call login(). If you call login() before init completes, it will fail silently.

Step 4 — Login

After init resolves, log the user in. For development, use one of the pre-created test UIDs: cometchat-uid-1 · cometchat-uid-2 · cometchat-uid-3 · cometchat-uid-4 · cometchat-uid-5 Add the login logic to your root component — replace the contents of src/app/app.ts. The component below uses an inline template, so the generated app.html and app.css are no longer used; you can delete them. Use CometChatUIKit.getLoggedinUser() to check for an existing session before calling login().
Angular 20+ names the root component App in src/app/app.ts, as below. A project created with Angular 17–19 uses AppComponent in src/app/app.component.ts — use that file and class name here and in main.ts instead.
src/app/app.ts
Key points:
  • getLoggedinUser() checks for an existing session so you don’t re-login unnecessarily.
  • login(uid) skips the API call if a session already exists and returns the cached user.
  • Components must not render until login resolves — gate rendering with @if on a signal.
  • Keep state that changes in a promise or subscription callback in a signal(). New Angular 21 projects are zoneless (no zone.js), so assigning a plain field there (this.isLoggedIn = true) doesn’t refresh the view — the app stays on “Loading…” and dev mode can throw NG0100: ExpressionChangedAfterItHasBeenChecked. Signals work the same with and without zone.js, so this code also runs on Angular 17–20.
For production, use loginWithAuthToken() instead of Auth Key. Generate tokens server-side via the REST API.

Step 5 — Add the CSS Import

CometChat components rely on CSS custom properties for theming. Add the stylesheet using one of these methods:
Without this import, components will render with broken or missing styles.

Register UIKit Assets

The UIKit ships icons, images, and audio files that Angular’s build system won’t serve automatically. Append the UIKit entry to the existing assets array in your angular.json (under architect.build.options) so they are copied to the build output:
angular.json
Keep the entries the CLI generated (public on Angular 18+; src/favicon.ico and src/assets on Angular 17) — replacing the array instead of appending to it stops your own static files from being served.
Skipping this step will cause all UIKit icons, empty-state images, and notification sounds to fail with 404 errors.

Raise the Production Bundle Budget

ng build uses the production configuration, whose default initial budget errors at 1 MB. The UI Kit and SDK put the initial bundle well above that — a production build of the app in this guide (UI Kit 5.2, the conversation list + message view layout) is about 4.4 MB raw (about 630 kB gzipped), on Angular 19 and 21 alike — so the build fails with bundle initial exceeded maximum budget. Raise the limit in angular.json, and list the SDK under allowedCommonJsDependencies to silence its CommonJS warning:
angular.json
Edit the existing initial entry in place and keep the anyComponentStyle budget the CLI generated. With these values a clean build of the sample app has no budget warning. The warning appears once the initial bundle passes 5 MB as you add your own code or optional packages such as the calling SDK; the 8 MB error leaves headroom before the build fails.

Step 6 — Choose a Chat Experience

Integrate a conversation view that suits your app’s UX. Each option below includes a step-by-step guide.

Conversation List + Message View

Two-panel layout — conversation list on the left, messages on the right. Think WhatsApp Web or Slack.
  • Two-panel layout with conversation list and active chat window
  • Switch between one-to-one and group conversations
  • Tap-to-view on mobile — tapping a conversation opens the message view
  • Real-time updates and message sync across sessions

Build Conversation List + Message View

Step-by-step guide to build this layout

One-to-One / Group Chat

Single chat window — no sidebar. Good for support chat, embedded widgets, or focused messaging.
  • Dedicated chat window for one-on-one or group messaging
  • No conversation list — users go directly into the chat
  • Full-screen experience optimized for mobile
  • Ideal for support chat or community messaging

Build One-to-One / Group Chat

Step-by-step guide to build this layout

Tab-Based Chat

Tabbed navigation — Chat, Call Logs, Users in separate tabs. Good for full-featured apps.
  • Tab navigation between Chat, Call Logs, and Users
  • Full-screen messaging within each tab
  • Unified experience for conversations, call history, and settings
  • Scales well for adding future features like notifications or contacts

Build Tab-Based Chat

Step-by-step guide to build this layout

Build Your Own Chat Experience

Need full control over the UI? Use individual components, customize themes, and wire up your own layouts.
  • Components — All prebuilt UI elements with inputs and customization options
  • Core Features — Messaging, real-time updates, and other capabilities
  • Theming — Colors, fonts, dark mode, and custom styling

Next Steps

Components Overview

Browse all prebuilt UI components

Theming

Customize colors, fonts, and styles

Core Features

Chat features included out of the box

Troubleshooting

Common issues and fixes