当你遇到Can't bind to 'ngForOf' since it isn't a known property of 'tr'. (" //无法绑定到“ngforof”,因为它不是“tr”的已知属性。(“
可能问题一:
当前错误原因是没有绑定ngforof,在@ngmodule()中添加browsermodule到imports:[],如果它是根模块(appmodule),则为commonmodule。
简而言之,就是根部app.module有没有导入这个基础模块,检查一下
可能问题二:出现此问题是你的导入有误,修改BrowserModule在控制器的位置
import {BrowserModule, CommonModule} from '@angular/common';
..
..
@NgModule({
imports: [BrowserModule, /* or CommonModule */],
..
})
可能问题三: 检查一下你的页面是否在当前自己所属模块执行了以下操作
举例:当前模块名字叫做 aa-management
aa-management模块下,当前页面名字叫做report
首先检查这个aa-management.module.ts代码
import { NgModule, Type } from '@angular/core';
import { SharedModule } from '@shared';
import { ManagementRoutingModule } from './hr-management-routing.module'; // 看看有没有这样一行代码-------1
import { HrReportComponent } from './hr-report/hr-report.component'
const COMPONENTS: Type<void>[] = [
HrReportComponent
];
@NgModule({
imports: [
SharedModule,
ManagementRoutingModule // 看看有没有这样一行代码-------2
],
declarations: COMPONENTS,
})
export class ManagementModule { }
然后检查一下:hr-management-routing.module.ts
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { ReportComponent } from './hr-report/hr-report.component' // 看看有没有这样一行代码-------3
const routes: Routes = [
{ path: 'report', component: ReportComponent }, // 看看有没有这样一行代码-------4
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class ManagementRoutingModule { }
如果以上都没问题,就OK