我做错了什么?

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 = "let talk of talks"

正确的:

*ngFor="let talk of talks"

其他回答

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

错误的:

*ngFor = "let talk of talks"

正确的:

*ngFor="let talk of talks"

在我的例子中,我没有在for循环中声明循环变量

<div *ngFor="pizza of pizzas; index as i">

而不是

<div *ngFor="let pizza of pizzas; index as i">

在声明了“let”之后,它就对我有用了。

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

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

)}

此语句用于Angular2 Beta版本.....

以后用let代替#

Let关键字用于声明局部变量

我错过了就让在前面说话:

<div *ngFor="let talk of talks">

注意到。使用#…不建议在NgFor等结构性指令中声明局部变量。用let代替。

<div *ngFor="#talk of talks">现在变成<div *ngFor="let talk of talks">

最初的回答:

我错过了#在谈话前:

<div *ngFor="#talk of talks">

我们很容易忘记#。我希望Angular的异常错误消息会说:you forget that # again。