我有相同的页面可以正常工作,但我不知道为什么这个页面不起作用。看起来错误发生在数组被填充之前。为什么?在我的另一个页面上,它是相同的服务并且可以正常工作。谢谢你的帮助。
HTML
<thead>
<tr>
<th>#</th>
<th>UserID</th>
<th></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let printShopPortalUser of printShopPortalUsers; let i = index">
<th scope="row">{{ i + 1 }}</th>
<td>{{ printShopPortalUser.userID }}</td>
</tr>
</tbody>
角
@NgModule({
imports: [
BrowserModule,
ReactiveFormsModule,
NgbModule
],
declarations: [
]
})
printShopPortalUsers: UserPrintShop[] = [];
ngOnInit() {
//The first method is returning an empty array ! while it works on another page
//this.printShopPortalUserService.findAll().pipe(first()).subscribe(printShopPortalUsers => this.printShopPortalUsers = printShopPortalUsers);
//This second method returns an array but the tr error happens before
this.printShopPortalUserService.findAll().pipe(first()).subscribe((res:UserPrintShop[])=>{
this.printShopPortalUsers = res;
console.log(res);
})
console.log(this.printShopPortalUsers);
}