Skip to content

Commit 9547f8c

Browse files
authored
Merge pull request #124 from GetStream/tutorial-fixes
docs: Fix tutorial after testing
2 parents bd0ea1c + ac3f11b commit 9547f8c

File tree

1 file changed

+42
-26
lines changed

1 file changed

+42
-26
lines changed

tutorial/tutorial.md

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ import { StreamChatModule } from 'stream-chat-angular';
5656
export class AppModule { }
5757
```
5858
59-
If you already use [ngx-translate](https://github.com/ngx-translate/core) in your application, follow [this](https://getstream.io/chat/docs/sdk/angular/concepts/translation/) guide to set up translation.
59+
If you already use [ngx-translate](https://github.com/ngx-translate/core) in your application, follow [our translation guide](https://getstream.io/chat/docs/sdk/angular/concepts/translation/) to set up translation.
6060
6161
2. Init the chat application
6262
6363
Replace the content of your `app.component.ts` with the following code:
6464
6565
```typescript
66-
import { Component } from "@angular/core";
66+
import { Component, OnInit } from "@angular/core";
6767
import {
6868
ChatClientService,
6969
ChannelService,
@@ -75,7 +75,7 @@ import {
7575
templateUrl: "./app.component.html",
7676
styleUrls: ["./app.component.scss"],
7777
})
78-
export class AppComponent {
78+
export class AppComponent implements OnInit {
7979
constructor(
8080
private chatService: ChatClientService,
8181
private channelService: ChannelService,
@@ -84,27 +84,35 @@ export class AppComponent {
8484
const apiKey = "YOUR_API_KEY";
8585
const userId = "USER_ID";
8686
const userToken = "USERT_TOKEN";
87-
void this.chatService.init(apiKey, userId, userToken);
88-
this.chatService.chatClient.channel("messaging", "talking-about-angular", {
89-
// add as many custom fields as you'd like
90-
image:
91-
"https://upload.wikimedia.org/wikipedia/commons/thumb/c/cf/Angular_full_color_logo.svg/2048px-Angular_full_color_logo.svg.png",
92-
name: "Talking about Angular",
93-
});
94-
void this.channelService.init({
87+
this.chatService.init(apiKey, userId, userToken);
88+
this.streamI18nService.setTranslation();
89+
}
90+
91+
async ngOnInit() {
92+
const channel = this.chatService.chatClient.channel(
93+
"messaging",
94+
"talking-about-angular",
95+
{
96+
// add as many custom fields as you'd like
97+
image:
98+
"https://upload.wikimedia.org/wikipedia/commons/thumb/c/cf/Angular_full_color_logo.svg/2048px-Angular_full_color_logo.svg.png",
99+
name: "Talking about Angular",
100+
}
101+
);
102+
await channel.create();
103+
this.channelService.init({
95104
type: "messaging",
96105
id: { $eq: "talking-about-angular" },
97106
});
98-
this.streamI18nService.setTranslation();
99107
}
100108
}
101109
```
102110
103111
First, we connect a user to the chat client. Further information about [connecting users](https://getstream.io/chat/docs/javascript/init_and_users/?language=javascript) is available in our platform documentation.
104112
105-
Next, we create a channel (if doesn't not exist) to test with. You can read more about [channel creation](https://getstream.io/chat/docs/javascript/creating_channels/?language=javascript) in out platform documentation.
113+
Next, we create a channel (if doesn't exist) to test with. You can read more about [channel creation](https://getstream.io/chat/docs/javascript/creating_channels/?language=javascript) in out platform documentation.
106114
107-
Lastly, we provide a filter condition for loading channels. If you want to more about [filtering channels](https://getstream.io/chat/docs/javascript/query_channels/?language=javascript), our platform documentation got you covered.
115+
Lastly, we provide a filter condition for loading channels. If you want to know more about [filtering channels](https://getstream.io/chat/docs/javascript/query_channels/?language=javascript), our platform documentation got you covered.
108116
109117
We also set up the translation for the application. If you want to customize it, check out our [translation guide](https://getstream.io/chat/docs/sdk/angular/concepts/translation/).
110118
@@ -166,7 +174,7 @@ Once you have the app running, you’ll notice the following out-of-the-box feat
166174
Stream Chat Angular supports dark and light themes, the default is the light theme, here is how you can switch to dark:
167175
168176
```typescript
169-
import { Component } from "@angular/core";
177+
import { Component, OnInit } from "@angular/core";
170178
import {
171179
ChatClientService,
172180
ChannelService,
@@ -179,7 +187,7 @@ import {
179187
templateUrl: "./app.component.html",
180188
styleUrls: ["./app.component.scss"],
181189
})
182-
export class AppComponent {
190+
export class AppComponent implements OnInit {
183191
constructor(
184192
private chatService: ChatClientService,
185193
private channelService: ChannelService,
@@ -189,19 +197,27 @@ export class AppComponent {
189197
const apiKey = "YOUR_API_KEY";
190198
const userId = "USER_ID";
191199
const userToken = "USERT_TOKEN";
192-
void this.chatService.init(apiKey, userId, userToken);
193-
this.chatService.chatClient.channel("messaging", "talking-about-angular", {
194-
// add as many custom fields as you'd like
195-
image:
196-
"https://upload.wikimedia.org/wikipedia/commons/thumb/c/cf/Angular_full_color_logo.svg/2048px-Angular_full_color_logo.svg.png",
197-
name: "Talking about Angular",
198-
});
199-
void this.channelService.init({
200+
this.chatService.init(apiKey, userId, userToken);
201+
this.streamI18nService.setTranslation();
202+
this.themeService.theme$.next("dark");
203+
}
204+
205+
async ngOnInit() {
206+
const channel = this.chatService.chatClient.channel(
207+
"messaging",
208+
"talking-about-angular",
209+
{
210+
// add as many custom fields as you'd like
211+
image:
212+
"https://upload.wikimedia.org/wikipedia/commons/thumb/c/cf/Angular_full_color_logo.svg/2048px-Angular_full_color_logo.svg.png",
213+
name: "Talking about Angular",
214+
}
215+
);
216+
await channel.create();
217+
this.channelService.init({
200218
type: "messaging",
201219
id: { $eq: "talking-about-angular" },
202220
});
203-
this.streamI18nService.setTranslation();
204-
this.themeService.theme$.next("dark");
205221
}
206222
}
207223
```

0 commit comments

Comments
 (0)