I am using 6.3 of NGX Data Table which cannot bind to an observable collection. How do I transform an Angular Observable Collection into a regular non-observable Array?
Here is what I have for the service:
private _productUrl = '../../api/todos/todos.json';
constructor(private _http: Http) { }
getToDos(): Observable<IToDo[]> {
return this._http.get(this._productUrl)
.map((response: Response) => <IToDo[]> response.json())
.do(data => console.log('All: ' + JSON.stringify(data)))
.catch(this.handleError);
}
Here is what I have for the component.ts. It gives me an error on the foreach loop: Cannot read property 'length' of undefined
ngOnInit() {
this._toDoService.getToDos()
.subscribe(
toDos => this.toDos = toDos,
error => this.errorMessage = <any>error);
this.rows = this.transform(this.toDos);
}
transform(source: IToDo[]): IToDo[] {
let dest: IToDo[] = [];
for (let sourceItem of source)
{
let destItem: IToDo = {
toDoId: sourceItem.toDoId,
name: sourceItem.name,
priority: sourceItem.priority,
dueDate: sourceItem.dueDate,
completed: sourceItem.completed
};
dest.push(destItem);
}
return dest;
}