angular报错信息之 Can't bind to 'ngForOf' since it isn't a known property of 'tr'. ("
文章 2976 0 0 0
发布时间:2019年10月15日

概述

angular报错信息之Can't bind to 'ngForOf' since it isn't a known property of 'tr'. (" 
//无法绑定到“ngforof”,因为它不是“tr”的已知属性。(“

当前错误原因是没有绑定ngforof,在@ngmodule()中添加browsermoduleimports:[],如果它是根模块(appmodule),则为commonmodule

vendor.js:30013 Uncaught Error: Template parse errors:
Can't bind to 'ngForOf' since it isn't a known property of 'tr'. ("
                </div>
                <tbody>
                  <tr [ERROR ->]ngFor="let item of companies; let i =index">
                     <td>{{i}}</td>
                 "): ng:///AppRoutingModule/ZmzSelectComponent.html@57:22
Property binding ngForOf not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations". ("
                </div>
                <tbody>
                  [ERROR ->]                     <td>{{i}}</td>
             "): ng:///AppRoutingModule/ZmzSelectComponent.html@57:18
    at syntaxError (vendor.js:30013)
    at TemplateParser.parse (vendor.js:42980)
    at JitCompiler._parseTemplate (vendor.js:51606)
    at JitCompiler._compileTemplate (vendor.js:51594)
    at vendor.js:51538
    at Set.forEach (<anonymous>)
    at JitCompiler._compileComponents (vendor.js:51538)
    at vendor.js:51451
    at Object.then (vendor.js:30004)
    at JitCompiler._compileModuleAndComponents (vendor.js:51450)

angular报错信息之 Can't bind to 'ngForOf' since it isn't a known property of 'tr'. ("

解决方法

出现此问题是你的组件顺序有误,修改BrowserModule在控制器的位置

import {BrowserModule, CommonModule} from '@angular/common';
..
..
@NgModule({
  imports: [BrowserModule, / or CommonModule /],
  ..
})
评论专区