我做错了什么?
import {bootstrap, Component} from 'angular2/angular2'
@Component({
selector: 'conf-talks',
template: `<div *ngFor="talk of talks">
{{talk.title}} by {{talk.speaker}}
<p>{{talk.description}}
</div>`
})
class ConfTalks {
talks = [ {title: 't1', speaker: 'Brian', description: 'talk 1'},
{title: 't2', speaker: 'Julie', description: 'talk 2'}];
}
@Component({
selector: 'my-app',
directives: [ConfTalks],
template: '<conf-talks></conf-talks>'
})
class App {}
bootstrap(App, [])
错误是
EXCEPTION: Template parse errors:
Can't bind to 'ngFor' since it isn't a known native property
("<div [ERROR ->]*ngFor="talk of talks">
发布于 2017-09-14 05:12:11
另一个导致OP错误的拼写错误可能是使用了in
<div *ngFor="let talk in talks">
您应该改用of
:
<div *ngFor="let talk of talks">
发布于 2019-06-25 10:44:51
在angular 7中,通过将以下行添加到.module.ts
文件中修复了此问题:
import { CommonModule } from '@angular/common'; imports: [CommonModule]
发布于 2019-10-10 17:24:33
你应该使用let关键字as来声明局部变量,例如*ngFor="let talk of talk“
https://stackoverflow.com/questions/34012291
复制相似问题