【发布时间】:2021-04-02 00:13:42
【问题描述】:
我有相同的页面,但我不知道为什么这个页面不起作用。看起来错误发生在数组被填充之前。为什么?在我的另一个页面上,它是相同的服务并且可以正常工作。感谢您的帮助。
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);
}
【问题讨论】:
-
请尝试在您的根模块中导入 BrowserModule,将 CommonModule 添加到子模块中。
-
你好Kevi Zhang,是的,浏览器模块在根模块中,我只导入了公共模块,但它是同样的错误。
-
您的项目中有多少个模块,只有一个?尝试运行此命令
ng build --prod你会得到什么 -
我得到了我在开发 src/app/services/UserPrintShopService.ts:18:33 中没有得到的错误 - 错误 TS2339:属性 'api' 不存在于类型 '{ production: boolean ; }'。 18个超级(_http,
${environment.api.baseUrl}usersprintshop);我得到了在开发模式下运行正常的其他页面和服务。 -
malbarmavi,我会在 2 小时内完成并把链接放在这里。
标签: html angular typescript ngfor angular11