Created
January 31, 2024 23:58
-
-
Save teomanofficial/2beb560b78411153ed3f196dc2856df7 to your computer and use it in GitHub Desktop.
Angular Writable Signals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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