zoukankan      html  css  js  c++  java
  • angular11报错Can't bind to 'ngForOf' since it isn't a known property of 'tr'. 三种排查办法以及解决方案

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

  • 相关阅读:
    Vue路由机制
    谷歌浏览器打不开应用商店的解决方法
    Vue报错——Component template should contain exactly one root element. If you are using vif on multiple elements, use velseif to chain them instead.
    Vue.js学习之——安装
    Vue使用axios无法读取data的解决办法
    关于localstorage存储JSON对象的问题
    2013年整体计划
    个人喜欢的警语收集
    Linux防火墙的关闭和开启
    Flex修改title 转载
  • 原文地址:https://www.cnblogs.com/sugartang/p/14689694.html
Copyright © 2011-2022 走看看