3

I have event coming in using socket.io and pushed it to array object, Now i see its being added to array but its not updating or binding to the view if click on that component then i see it gets updated , Do we have something like ng-blur options in angular 4 so we can achieve this task ?

secondConfigObject.data is datasource of data grid i am using.

stream.component.ts

ngOnInit() {
        this.socket.on('newMessage', (newEvent) => {
            console.log('New Event', newEvent);
             this.sortArray(newEvent);
        });
}

sortArray(newEvent){
  var streamArray = this.secondConfigObject.data;
streamArray.push(Object.assign({},newEvent.data));

}
1
  • You have bad history of marking answers :) Commented Feb 8, 2018 at 20:05

1 Answer 1

4

you can manually trigger using ChangeDetectorRef

constructor(private cdr:ChangeDetectorRef) {
}

sortArray(newEvent){
  var streamArray = this.secondConfigObject.data;
  streamArray.push(Object.assign({},newEvent.data));
  this.cdr.detectChanges(); 
}
Sign up to request clarification or add additional context in comments.

5 Comments

detectChanges() saves my life once per week
and i thought i was the Angular master....did not even know that smth like ChangeDetectorRef existed....thank you very much. +1
so that resolved partial issue when i have new event that got inserted but when i update existing event that is not updating i have to click outside of the grid
Do i need to do something like this ` this.secondConfigObject.data = [..streamArray]` before i execute detectChanges()
whatever changes you need make sure you have it before detectchanges

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.