1

I am doing coding angular 4. I have a web socket and i am able to log message coming on web socket with console.log() , but when I update variable with that message same is not getting reflected on UI. Please find the code below.

constructor(private zone: NgZone, private cdRef: ChangeDetectorRef, private DataService1: DataService, private calcSevice: PostService, private datepipe: DatePipe, private elementRef: ElementRef) {
    this.ws = new SockJS(this.serverUrl);
    this.stompClient = Stomp.over(this.ws);
    let that = this;
    this.stompClient.connect({}, function (frame) {
      that.stompClient.subscribe("/updates/public", (message) => {
        //this.zone.run(() => {
        alert("got message");
        this.refreshErrorMessage = message.body;
        console.log("Message from socket is" + this.refreshErrorMessage);
      });

      //});
    });
}

I thought that this is an issue with zone so i put code for ngzone as commented above in two lines but then it gave me Cannot read property 'run' of undefined error. Please help

Amit G
  • 11
  • 3

0 Answers0