Back to Copilotkit

injectChatLabels

showcase/shell-docs/src/content/reference/angular/functions/injectChatLabels.mdx

1.61.11.8 KB
Original Source

Overview

injectChatLabels returns the full set of CopilotChatLabels in scope: any labels you provided through provideCopilotChatLabels merged over COPILOT_CHAT_DEFAULT_LABELS. If no labels were provided, it returns the defaults unchanged.

It reads the COPILOT_CHAT_LABELS injection token (optionally), so it must run inside an Angular injection context (a constructor, a field initializer, or a factory). The prebuilt chat components call it internally; use it directly when you build your own chat UI and want the same configurable strings.

Signature

ts
import { injectChatLabels } from "@copilotkit/angular";

function injectChatLabels(): CopilotChatLabels;

Return Value

Returns a complete CopilotChatLabels object. Because the value is the merge of your overrides over the defaults, every field is always present (never undefined).

Usage

Call it from an injection context and read the labels you need.

ts
import { Component } from "@angular/core";
import { injectChatLabels } from "@copilotkit/angular";

@Component({
  selector: "app-my-chat",
  standalone: true,
  template: `<input [placeholder]="labels.chatInputPlaceholder" />`,
})
export class MyChatComponent {
  protected readonly labels = injectChatLabels();
}
<Cards> <Card title="provideCopilotChatLabels" description="Provide the label overrides that this function merges over the defaults." href="/reference/angular/functions/provideCopilotChatLabels" /> <Card title="CopilotChat" description="The prebuilt chat component that uses these labels internally." href="/reference/angular/components/CopilotChat" /> </Cards>