在Angular 5中调用.connect Web套接字方法后无法重新分配值

时间:2019-02-13 10:50:20

标签: angular angular5

使用Web套接字单击特定用户后,我试图更新网站磁贴数。但是HTML UI中的值未更新。下面是我的代码。

    export class LiveTrackingComponent implements OnInit {
    this.UserCount:Number=0;
    constructor(private http: Http)
    }
    initializeWebSocketConnection() {
            let ws = new WebSocket( 'http://192.155.1.15:8080/WebSocketMethod' );
            this.stompClient = Stomp.over( ws );
            let that = this;
            let token = localStorage.getItem( 'Token' );
            let de_id=localStorage.getItem('de_id');
            let bid = ( JSON.parse( localStorage.getItem( 'bid' ) ));
            this.stompClient.connect( { token },function( frame ) {
                that.stompClient.subscribe( '/topic/public/' + businesss, ( message ) => {
                    if ( message.body ) {
                        console.log( message.body );
                    }
                } );
                that.stompClient.send( "/app/chat.getdevice", {}, SON.stringify( {'b_de_ids':de_id,'bid': bid} ) );
                that.stompClient.subscribe( '/topic/bid/' + bid, ( message ) => {
                    if ( message.body ) {
                        this.websocketData = JSON.parse( message.body );
                        let temp = this.websocketData.countdata
                        for ( let i = 0; i < temp.length; i++ ) {
                            let alert_temp = temp[i].alert_name;
                            if ( alert_temp == "UserCnt" ) {
                               this.UserCount = temp[i].alert_count;
                                console.log( this.UserCount );
                            }                         }
                        }
                    }
                } );
            } );
        }
    }

HTML Code

    <p>
      <span>{{(UserCount)}}</span></p>

这里....我已经声明了UserCount变量,并且我正尝试在Web套接字调用之后更新this.UserCount值...

在侧面Socket中,this.UserCount变量第二次声明,并且在HTML中仍显示0。

0 个答案:

没有答案