Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 特定于ngFor每个项目的角度提取数据_Angular_Typescript_Asynchronous_Observable_Ngfor - Fatal编程技术网

Angular 特定于ngFor每个项目的角度提取数据

Angular 特定于ngFor每个项目的角度提取数据,angular,typescript,asynchronous,observable,ngfor,Angular,Typescript,Asynchronous,Observable,Ngfor,我有一个项目数组,这些项目本身有一个“外键”,可以唯一地标识基于服务器的其他项目 <div *ngFor="let parentItem of parentItems"> {{(getChild(parentItem.childId) | async)?.someData}} </div> getChild(id):Observable<IChild>{ return this.childService.getChild(id); } {{(ge

我有一个项目数组,这些项目本身有一个“外键”,可以唯一地标识基于服务器的其他项目

<div *ngFor="let parentItem of parentItems">
  {{(getChild(parentItem.childId) | async)?.someData}}
</div>

getChild(id):Observable<IChild>{
  return this.childService.getChild(id);
}

{{(getChild(parentItem.childId)|异步)?.someData}
getChild(id):可观察{
返回此.childService.getChild(id);
}
我想嵌套这些项目并显示它们。 遗憾的是,在子括号中没有显示任何内容,即使在登录到控制台时,值在常规订阅服务器中也正确显示。
此外,似乎还有另一个问题。程序一直尝试重新蚀刻它。我认为这与更改检测有关,但我不知道如何解决此问题。

为什么不这样做:

// component
public children$: Observable<Child>[]
constructor(childService: ChildService) {
  children$ = parentItems.map((parentItem) => this.childService.getChild(parentItem.childId).pipe(
     (data) => data.someData
  ));
}
//组件
公共儿童$:可观察[]
构造函数(儿童服务:儿童服务){
children$=parentItems.map((parentItem)=>this.childService.getChild(parentItem.childId).pipe(
(数据)=>data.someData
));
}

//模板
{{child$| async}}

这可能是更好的方法,而不是在循环时获取记录。这样,在循环开始执行之前,所有记录都已存储在内存中。
// template
<div *ngFor="let child$ of children$">
   {{ child$ | async }}
</div>