I have developed a feature that displays users who are online. While it works perfectly in the console log, I am struggling to show p as the result if the user is online. Below is the code snippet:
ngOnInit() {
this.socket.emit('online', { room: 'global', user: this.user.username });
this.socket.on('refreshPage', () => {
this.GetUserData(this.name);
});
...
...
ngAfterViewInit() {
this.socket.on('usersOnline', data => {
console.log(data);
});
}
The console.log(data) above shows the details of all users who are currently online in the console. How can I modify this to display a condition on the front-end instead? We attempted something like this:
CheckIfOnline(name) {
const result = _.indexOf(this.onlineusers, name);
if (result > -1) {
return true;
} else {
return false;
}
}
HTML
<p class="" *ngIf="CheckIfOnline(user.username)">online</p>
Unfortunately, the paragraph does not show up because there seems to be a missing element in the CheckIfOnline function. This function was set up as a prototype but I believe it should work with ngAfterViewInit. Can you suggest how to replace the console.log and correct the checkifonline function so they interact properly and display the p tag when the user is online?