我做错了什么?

import {bootstrap, Component} from 'angular2/angular2'

@Component({
  selector: 'conf-talks',
  template: `<div *ngFor="let talk in 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 'ngForIn' since it isn't a known native property
("<div [ERROR ->]*ngFor="let talk in talks">

当前回答

简单地把“in”改成“of”就解决了同样的问题。

Chnage <div *ngFor="let talk in talks">

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

其他回答

我的解决方案是-只需从表达式^__^中删除'*'字符

<div ngFor="let talk in talks">

在我的情况下,WebStrom自动完成插入小写*ngfor,即使看起来你选择了正确的驼峰大小写(* ngfor)。

我的问题是,Visual Studio在复制粘贴时自动将*ngFor小写为*ngFor。

如果你想使用of而不是切换到in,还有另一种选择。您可以使用6.1中介绍的KeyValuePipe。你可以很容易地迭代一个对象:

<div *ngFor="let item of object | keyvalue">
  {{item.key}}:{{item.value}}
</div>

尝试从'@angular/common'导入import {CommonModule};angular final中的*ngFor,*ngIf都存在于CommonModule中