File tree 3 files changed +7
-1
lines changed
3 files changed +7
-1
lines changed Original file line number Diff line number Diff line change 3
3
< h2 > Received messages</ h2 >
4
4
< ol >
5
5
<!-- we will use Angular binding to populate list of messages -->
6
- < li class ="message "> message</ li >
6
+ < li class ="message " *ngFor =" let message of receivedMessages " > {{ message}} </ li >
7
7
</ ol >
8
8
</ div >
Original file line number Diff line number Diff line change 1
1
import { Component , OnInit } from '@angular/core' ;
2
2
import { RxStompService } from '@stomp/ng2-stompjs' ;
3
+ import { Message } from '@stomp/stompjs' ;
3
4
4
5
@Component ( {
5
6
selector : 'app-messages' ,
6
7
templateUrl : './messages.component.html' ,
7
8
styleUrls : [ './messages.component.css' ]
8
9
} )
9
10
export class MessagesComponent implements OnInit {
11
+ public receivedMessages : string [ ] = [ ] ;
10
12
11
13
constructor ( private rxStompService : RxStompService ) { }
12
14
13
15
ngOnInit ( ) {
16
+ this . rxStompService . watch ( '/topic/demo' ) . subscribe ( ( message : Message ) => {
17
+ this . receivedMessages . push ( message . body ) ;
18
+ } ) ;
14
19
}
15
20
16
21
onSendMessage ( ) {
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ export const myRxStompConfig: InjectableRxStompConfig = {
23
23
24
24
// Will log diagnostics on console
25
25
// It can be quite verbose, not recommended in production
26
+ // Skip this key to stop logging to console
26
27
debug : ( msg : string ) : void => {
27
28
console . log ( new Date ( ) , msg ) ;
28
29
}
You can’t perform that action at this time.
0 commit comments