當你遇到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