我做错了什么?

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

当前回答

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

其他回答

TL; diana;

使用让…而不是let…在! !


如果你刚接触Angular (>2.x),而且可能是从Angular1迁移过来的。X,很可能你把它和of搞混了。正如andreas在下面的评论中提到的……Of迭代对象的值,而for…In迭代对象中的属性。这是ES2015中引入的新特性。

简单地替换:

<!-- Iterate over properties (incorrect in our case here) -->
<div *ngFor="let talk in talks">

<!-- Iterate over values (correct way to use here) -->
<div *ngFor="let talk of talks">

因此,你必须将in替换为ngFor指令中的of来获取值。

基本上,如果你用一个新类创建一个弹出窗口,那么在那个时候你必须把那个类添加到

declarations: []

在base。module.ts或app。module.ts中

我的示例代码

########################## 我的组件 ##################################

@Component({
  selector: 'app-modal-content',
  templateUrl: './order-details.html',
  encapsulation: ViewEncapsulation.None,
  styles: []
})

export class NgbdModalContent {
  @Input() orderDetails: any;
  private orderId;
  private customer;
  private orderDate;
  private shipDate;
  private totalAmount;
  private salesTax;
  private shippingCost;
  private transactionStatus;
  private isPaid;
  private isMailSent;
  private paymentDate;

  // private orderDetails;

  constructor(public activeModal: NgbActiveModal) {
  }
}

########################### 基础模块 #################################

@NgModule({
    imports: [
        CommonModule,
        FormsModule
    ],
  declarations: [
    NavbarsComponent,
    NgbdModalContent,
  ]
})
export class BaseModule { }

为了增加更多的问题,我天真地发现,如果你不使用let语句来分配循环的索引,你也会得到同样的错误:

<span *ngFor="let button of buttons; i: index; trackBy: trackBy">
...
</span>

也抛出相同的错误。下面的版本修复了它

<span *ngFor="let button of buttons; let i = index; trackBy: trackBy">
...
</span>

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

Q:不能绑定到'pSelectableRow',因为它不是'tr'的已知属性。

答:你需要在ngmodule中配置primeng tabulemodule