我正在使用 6.3 的 NGX 数据表,它无法绑定到可观察的集合。如何将 Angular 可观察集合转换为常规不可观察数组?
这是我的服务:
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);
}
这是我为 component.ts 准备的。它在 foreach 循环中给了我一个错误:无法读取未定义的属性“长度”
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;
}