使用 *ngFor *ngIf 时报错 Can't bind to 'ngForOf' since it isn't a known property of 'div'

使用 *ngFor 时报错:Can't bind to 'ngForOf' since it isn't a known property of 'container'。

原因是每一个组件必须单独有一个 module ,这应该是 angular 10 以后的规定吧。

下面写一下怎么改成 module 模式

Can‘t bind to ‘ngForOf‘ since it isn‘t a known property of ‘container‘_angular

app-routing.module.ts

const routes: Routes = [
  {
    path: 'home',
    loadChildren: () => import('./home/home.module').then(m => m.HomeModule),
  },
  {
    path: '',
    redirectTo: '/download',
    pathMatch: 'full'
  },
];

home.module.ts

import { NgModule } from '@angular/core';

import { CommonModule } from '@angular/common';
import { HomeComponent } from './home.component';
import { RouterModule } from '@angular/router';

@NgModule({
  declarations: [
    HomeComponent
  ],
  imports: [
    CommonModule,
    RouterModule.forChild([
      {
        path: '',
        component: HomeComponent,
      }
    ])
  ]
})
export class HomeModule { }