Angular Chat - Render Images
To render an image in a Chat, set the message type to "image" and specify the src field with the image URL. In the following example, AI sends a message with the "imageResponse" type, which is then converted into an image in Chat.
NOTE
Chat displays either images or text in a single message. Specify messageTemplate to display custom messages.
app.component.ts
- export class AppComponent {
- handleAIResponse() {
- if (aiResponse.type === "imageResponse") {
- const imageMessage = ({
- type: "image",
- src: aiResponse.imageUrl,
- author: "bot"
- });
- }
- this.messages = [...this.messages, imageMessage];
- }
- }