I am fetching data from Firebase and I expect my component view should update when data available but it was taking more than 15 sec
to update data on the view. Following is my component and template code.
There is some delay between data availability and view binding in my case, why? Or how to notify Angular to data get updated so update the view immediately?
@Component({
...
})
export class BoardComponent implements OnInit {
private db: firebase.database.Database;
public boards: Array<any>;
constructor(private route: ActivatedRoute,
private authService: AuthService) {
this.db = firebase.database();
this.boards = new Array<any>();
}
ngOnInit() {
this.loadBoards();
}
loadBoards() {
var ref = this.db.ref('/boards');
ref.on('child_added', (child) => {
console.log("Question added! adding data one by one");
var obj = child.val();
obj.key = child.key;
this.boards.push(obj);
});
}
}
Template :
...
<tr *ngFor="let item of boards">
<td>{{item.name}}</td>
</tr>
...