Angular Chat App Tutorial

Stream makes building in-app chat with Angular a seamless process. Using Angular components you can build a full chat app with threads, message replies, message reactions, message attachments, and so much more. You'll also learn how to customize components.

Set Up Your Angular Environment

The easiest way to build a Stream Chat Angular application from this tutorial is to create a new project using Angular CLI. Angular CLI builds an Angular boilerplate application that you can run locally with just a few simple commands.

Before you start: Make sure you've installed Angular CLI globally.

The SDK supports Angular versions from 12-17, you can complete the tutorial using any version. Angular 17 code snippets use standalone components, other versions are using module-based components.

Create a new application with Angular CLI:

Note You can use other style language if you wish.

Install the necessary dependencies:

  1. Angular 17
  2. Angular 16
  3. Angular 15
  4. Angular 14
  5. Angular 13
  6. Angular 12

Create a WhatsApp or Facebook Messenger Style Chat App

Stream's Angular Chat messaging SDK component library includes everything you need to build a fully functioning chat experience, supporting rich messages, reactions, image uploads, and more. This library was designed to enable you to get an application up and running quickly and efficiently while supporting customization for complex use cases.

We’ve included a few Stream Angular Chat examples to show you what’s possible:

  • Basic chat components cxample
  • Customizable UI components example

Build a Basic Chat App with Stream’s Core Angular Components

In the sample below, you’ll find the following basic chat components of the Angular library:

  • ChannelList
  • Channel
  • ChannelHeader
  • MessageInput
  • MessageList
  • Thread

To get started:

  1. Import the modules

Replace the src/app/app.config.ts file with the following:

Add other modules to your AppComponent:

Replace the content of your AppModule with the following code:

This will import the TranslateModule and the StreamChatModule.

If you already use ngx-translate in your application, follow our translation guide to set up translation.

In an effort to keep our bundle size small in the long run our SDK uses an architecture where integrators can decide to opt-out of certain costly (in terms of bundle size) features, this decision happens at module import, in the above example we chose what type of textarea component we want to use (StreamAutocompleteTextareaModule). You can find more information about this topic in our opt-in architecture guide.

  1. Init the chat application

Replace the content of your app.component.ts with the following code:

First, we connect a user to the chat client. Further information about connecting users is available in our platform documentation.

Next, we create a channel (if doesn't exist) to test with. You can read more about channel creation in our platform documentation.

Lastly, we provide a filter condition for loading channels. If you want to know more about filtering channels, our platform documentation got you covered.

We also set up the translation for the application. If you want to customize it, check out our translation guide.

  1. Create the chat UI

Replace the content of the app.component.html with the following code:

  1. Import CSS

Add the following code to your root stylesheet (styles.scss if you are using SCSS):

Important note If you are using CSS stylesheets, you should add the following import instead:

The SDK lets you create your own responsive layout, the code above contains a minimal setup where the channel list is displayed next to the channel component.

  1. Modify tsconfig.json

Add the following option to the compilerOptions in tsconfig.json file:

We need to enable synthetic default imports becuase the stream-chat library uses them.

  1. Start the application

Run the following command:

Once you have the app running, you’ll notice the following out-of-the-box features:

  • User online presence
  • Message status indicators (sending, received)
  • User role configuration
  • Message read indicators
  • Message reactions
  • URL previews (send a link to see it in action, for example, https://getstream.io/)
  • GIFs (type /giphy in the message input)
  • Threads
  • File uploads and previews
  • AI-powered spam and profanity moderation

Creating Your Own UI Components

If the built-in theming capabilities are not enough for you, you can create your own custom components.

In the below example, you’ll create custom ChannelPreview and Message components.

  1. Create the Message component

Run the following command:

  1. Implement the Message component

Replace the content of the message.component.ts with the following code:

  1. Use the custom message component

Provide the customMessageTemplate to the CustomTemplatesService:

In the HTML of your AppComponent:

In the component class of your AppComponent

  1. Create the ChannelPreview component

Run the following command:

  1. Implement the ChannelPreview component

Replace the content of the channel-preview.component.ts with the following code:

  1. Use the custom channel preview component

Provide the customChannelPreviewtemplate to the CustomTemplatesService:

In the HTML of your AppComponent

In the component class of your AppComponent

References

To learn more about the Angular SDK, check our SDK documentation and guides:

Final Thoughts

In this chat app tutorial we built a fully functioning Angular messaging app with our Angular SDK component library. We also showed how easy it is to customize the behavior and the style of the Angular chat app components with minimal code changes.

Both the chat SDK for Angular and the API have plenty more features available to support more advanced use-cases such as push notifications, content moderation, rich messages and more. Please check out our Android tutorial too. If you want some inspiration for your app, download our free chat interface UI kit.

Give us Feedback!

Any requests? Use the form below to connect directly with our dev team and tell us about your experience working with the Angular SDK:

Kiddom logo

We’ve been going at lightspeed to build more communication functionality into Kiddom. The only way to achieve this in four months was to do a chat integration with Stream because we needed to do it reliably and at scale.

Head of Product, Kiddom profile picture

Nick Chen

Head of Product, Kiddom

Next Steps

Create your free Stream account to try out all our Chat product has to offer. No commitment or credit card required. If you want a custom plan or have questions, we are eager to talk with you.

Activity Feeds

Build any kind of feed without the headache of scalability or reliability of your feeds.

Learn more about $ Activity Feeds

Enterprise

Available 99.999% uptime SLAs and industry-leading security to power the world's largest apps.

Learn more about $ Enterprise