gpt4 book ai didi

angular - 无法绑定(bind)到 'ngForOf',因为它不是 Angular 9 中 'tr' 的已知属性

转载 作者:行者123 更新时间:2023-12-03 15:27:43 28 4
gpt4 key购买 nike

ngFor在我的应用程序中不起作用。
我将我的应用程序拆分为单独的模块并包含 import { CommonModule } from '@angular/common';进入我的子模块和import { BrowserModule } from '@angular/platform-browser';进入我的app.modules.ts文件,但我仍然收到以下错误。

Can't bind to 'ngForOf' since it isn't a known property of 'tr'.
我曾尝试查看其他问题,但所有这些问题都只是对 include CommonModule 说的。 ,我就是。
这些是我的文件:
crud-list.component.html
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Id</th>
</tr>
</thead>
<tbody>
<tr *ngFor='let item of cruds'>
<td>{{item.OrderNumber}}</td>
</tr>
</tbody>
</table>
crud-list.component.ts
import { Component, OnInit } from '@angular/core';
import { CrudRequestService } from '@modules/crud/crud-services/crud-request.service';

@Component({
selector: 'app-crud-list',
templateUrl: './crud-list.component.html',
styleUrls: ['./crud-list.component.scss']
})
export class CrudListComponent {
public cruds: Array<any>;

constructor(private objService: CrudRequestService) {
this.objService.get().subscribe(
(oDataResult: any) => { this.cruds = oDataResult.value; },
error => console.error(error)
);
}
}
crud.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Routes, RouterModule } from '@angular/router';

import { CrudListComponent } from '@modules/crud/crud-list/crud-list.component';
import { CrudFormComponent } from '@modules/crud/crud-form/crud-form.component';
import { CrudComponent } from '@modules/crud/crud.component';

const routes: Routes = [
{
path: '', component: CrudComponent, children: [
{ path: '', component: CrudListComponent },
{ path: 'create', component: CrudFormComponent },
{ path: 'edit/:id', component: CrudFormComponent }
]
},
];

@NgModule({
imports: [CommonModule, RouterModule.forChild(routes)],
declarations: [CrudComponent]
})

export class CrudModule { }
app.module.ts
/* all the imports */

@NgModule({
declarations: [
AppComponent,
ForbidenAccessComponent,
PageNotFoundComponent,
AppHeaderComponent,
AppFooterComponent
],
imports: [
BrowserModule,
HttpClientModule,
NgbModule,
AppRoutingModule,
CoreModule
],
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: JwtInterceptor,
multi: true,
},
BreadcrumbsService,
AccordionService,
ModalService,
RequestService,
IdentityProviderService
],
bootstrap: [AppComponent]
})
export class AppModule { }
应用程序路由.module.ts
/* imports */

const routes: Routes = [
{ path: 'home', canActivate: [AuthGuard], component: HomeComponent },
{ path: 'crud', canActivate: [AuthGuard], loadChildren: () => import('@modules/crud/crud.module').then(m => m.CrudModule)},
{ path: '', redirectTo: '/home', pathMatch: 'full' },
// The error status pages
{ path: '403', component: ForbidenAccessComponent },
{ path: '404', component: PageNotFoundComponent },
{ path: '**', redirectTo: '/404' }
];

@NgModule({
imports: [
CommonModule,
RouterModule.forRoot(routes)
],
exports: [RouterModule]
})
export class AppRoutingModule { }

最佳答案

当我在 stackblitz 中重新创建您的问题时,我没有问题。

https://stackblitz.com/edit/angular-60533597

确保将组件添加到模块 declarations以及 Routes .

关于angular - 无法绑定(bind)到 'ngForOf',因为它不是 Angular 9 中 'tr' 的已知属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60533597/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com