我做错了什么?

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">

当前回答

有同样的问题,因为我使用了 *ngFor='for let card of cards' 而不是: *ngFor='let card of cards'

一开始就有一些for循环这里错了吗 它工作了,但有错误

其他回答

你应该使用let关键字来声明局部变量 e.g. *ngFor="让我们谈谈吧"

对我来说,长话短说,我无意中降到了角- β -16。

让…语法只在2.0.0-beta.17+中有效

如果在这个版本以下的任何版本上尝试let语法。您将生成这个错误。

要么升级到angular-beta-17,要么在items语法中使用#item。

对我来说,在app.module.ts文件中没有正确导入组件。导入后一切工作正常

@NgModule({
    declarations: [
      YourComponent,
      OtherComponents
    ],
    
    imports: [...]

)}

在我的例子中,它是一个小字母f。 我分享这个答案只是因为这是谷歌的第一个结果

确保写*ngFor

在我的例子中,=和"之间应该没有空格,

错误的:

*ngFor = "let talk of talks"

正确的:

*ngFor="let talk of talks"