Skip to content

Instantly share code, notes, and snippets.

@teomanofficial
Created January 31, 2024 23:58
Show Gist options
  • Save teomanofficial/2beb560b78411153ed3f196dc2856df7 to your computer and use it in GitHub Desktop.
Save teomanofficial/2beb560b78411153ed3f196dc2856df7 to your computer and use it in GitHub Desktop.
Angular Writable Signals
export class ChatRoomComponent implements OnInit {
onlineUsersCount: WritableSignal<number> = signal(0)
ngOnInit() {
// Update count via setter
app.events.on('chat.room.connected', () => {
this.onlineUsersCount.set(this.onlineUsersCount() + 1);
});
// Update count via callback
app.events.on('chat.room.connected', () => {
this.onlineUsersCount.update(value => value + 1);
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment