Javascript 角度9找不到不同的支撑对象';[对象对象]';类型为';对象';。NgFor只支持绑定到数组之类的可重用文件
我在模板中使用异步管道进行可观察:Javascript 角度9找不到不同的支撑对象';[对象对象]';类型为';对象';。NgFor只支持绑定到数组之类的可重用文件,javascript,arrays,angular,observable,typescript-typings,Javascript,Arrays,Angular,Observable,Typescript Typings,我在模板中使用异步管道进行可观察: applicants$: Observable<UserProfile[]>; ngOnInit() { this.applicants$ = this.store.pipe( select(fromRootUserProfileState.getUserProfiles) ) as Observable<UserProfile[]>; } 这是userProfile.service getUser
applicants$: Observable<UserProfile[]>;
ngOnInit() {
this.applicants$ = this.store.pipe(
select(fromRootUserProfileState.getUserProfiles)
) as Observable<UserProfile[]>;
}
这是userProfile.service
getUserProfiles(): Observable<UserProfile[]> {
return this.http.get<UserProfile[]>(
this.baseUrl + 'userprofiles/getuserprofiles'
);
}
getUserProfiles():可观察{
返回this.http.get(
this.baseUrl+'userprofiles/getuserprofiles'
);
}
在我使用ngFor的模板中,我使用异步管道迭代了Observable:
<mat-form-field
fxFlex="22"
appearance="outline"
*ngIf="applicants$ | async as applicants"
>
<mat-label>Applicant</mat-label>
<mat-icon matPrefix>person</mat-icon>
<mat-select
placeholder="Applicant"
name="applicant"
[(ngModel)]="this.searchPurchaseOrder.applicantId"
>
<mat-option *ngFor="let ap of applicants" [value]="ap.id">
ap.fullName
</mat-option>
</mat-select>
</mat-form-field>
申请人
人
美联社全名
但是,以下是我得到的错误:
这是存储中的数据形状。它正在填充,因此没有问题:
尝试使用别名为的管道:
让申请者的ap | async
这里的问题是您试图使用ngFor在对象中循环(这是不可能的)。如果您可以从“网络”选项卡发布响应预览,则有助于更好地了解该问题。您需要使用keyvalue管道在对象中循环,就像它是一个数组一样
{{applicator.key}}:{{applicator.value}
这也适用于异步管道,例如:
<div *ngFor="let item of (object$ | async) | keyvalue">
感谢“回答”此模板更改对我的案例有效:
<mat-form-field
fxFlex="22"
appearance="outline"
*ngIf="this.applicants$ | async | keyvalue as applicants">
<mat-label>Applicant</mat-label>
<mat-icon matPrefix>person</mat-icon>
<mat-select
placeholder="Applicant"
name="applicant"
[(ngModel)]="this.searchPurchaseOrder.applicantId">
<mat-option
*ngFor="let applicant of applicants"
[value]="applicant.value.id">
{{ applicant.value.fullName }}
</mat-option>
</mat-select>
</mat-form-field>
申请人
人
{{applicator.value.fullName}
如果您从后端获取数据。。。。。像node Mongo一样,遵循这种方法
res.status().json({data:[yourdata]})
现在你什么都不用做了
祝您编码愉快。您能检查一下您的商店是否有这些数据吗?另外,console.log()要查看该数据的格式,我已在末尾添加了数据剪切。响应预览数据将在末尾添加。请尝试使用。尝试删除ngIf'*ngIf=“applicators$”中的异步管道,并使用ng上的异步管道,如我先前建议的那样,并查看其是否有效。异步管道已事先应用。如果我像您所说的那样使用它,我会得到以下错误:错误错误:InvalidPipeArgument:“[object object]”用于管道“AsyncPipe”
<div *ngFor="let item of (object$ | async) | keyvalue">
<mat-form-field
fxFlex="22"
appearance="outline"
*ngIf="this.applicants$ | async | keyvalue as applicants">
<mat-label>Applicant</mat-label>
<mat-icon matPrefix>person</mat-icon>
<mat-select
placeholder="Applicant"
name="applicant"
[(ngModel)]="this.searchPurchaseOrder.applicantId">
<mat-option
*ngFor="let applicant of applicants"
[value]="applicant.value.id">
{{ applicant.value.fullName }}
</mat-option>
</mat-select>
</mat-form-field>