小编sa_*_*130的帖子

角度4:无法绑定到'ngForFor',因为它不是'li'的已知属性

我刚刚开始学习角度4.这是一个简单的代码,我试图在Visual Studio代码中实现,但不断收到此错误.

Uncaught Error: Template parse errors:
Can't bind to 'ngForFor' since it isn't a known property of 'li'. ("
</ul>
<ul>
 <li [ERROR ->]*ngFor="let hobby for hobbies">{{hobby}}</li>
</ul>"): ng:///AppModule/UserComponent.html@6:6
Property binding ngForFor 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".("
</ul>
<ul>
[ERROR ->]<li *ngFor="let hobby for hobbies">{{hobby}}</li>
</ul>"): ng:///AppModule/UserComponent.html@6:2
Run Code Online (Sandbox Code Playgroud)

我尝试过将CommonModule添加到app.module文件的先前解决方案.但它还没有解决问题.我无法弄清楚出了什么问题.

app.component.ts:

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

@Component({
  selector: 'app-root', …
Run Code Online (Sandbox Code Playgroud)

typescript angularjs-ng-repeat ngfor angular

6
推荐指数
1
解决办法
8359
查看次数

标签 统计

angular ×1

angularjs-ng-repeat ×1

ngfor ×1

typescript ×1