I have a problem. I found lots of information that async pipe expects Observables. So, I thought that I return observable from my service on socket.on event, but seems like I am wrong. How should I correctly implement that?
service:
public getUsers(): Observable<any> {
return new Observable<any>(observer => {
this.socket.on('my_users', (data) => observer.next(data));
});
}
component:
users: Observable<any[]>;
this.http.getUsers().subscribe((user: any) => {
this.users = user.data;
});
template:
<button class="send_to_username"
value="{{user}}"
*ngFor='let user of users; let i = index'
[ngClass]="{'active':isClicked[i]}"
(click)="isClicked[i] = (isClicked[i]? false :true); getReceiver(user)"
>{{user | async}}</button>
server:
@socketio.on('username', namespace='/private')
def receive_username(username):
users[username] = request.sid
print('Username added!')
print(users)
emit('my_users',
{'data': list(users.keys())})
ERROR Error: "InvalidPipeArgument: '111111' for pipe 'AsyncPipe'"
asyncpipe there? Theuservalue there is not an observable. There error is telling you that the value is'111111'. - Daniel W Strimpel