【问题标题】:"Can't bind to 'ngFor' since it isn't a known native property"“无法绑定到‘ngFor’,因为它不是已知的原生属性”
【发布时间】:2016-10-03 21:57:19
【问题描述】:

无法告诉我在这里做错了什么。尝试通过 CORE_DIRECTIVES 明确定义 ngFor 指令,并使用 let。有什么我错过的吗?

import { Component, Input , Output , EventEmitter} from 'angular2/core';
import {CORE_DIRECTIVES, FORM_DIRECTIVES} from 'angular2/common';

@Component({
  selector: 'panel',
  moduleId: module.id,
  templateUrl: './panel.component.html',
  styleUrls: ['./panel.component.css'],
  directives: [FORM_DIRECTIVES, CORE_DIRECTIVES]
})

export class panelComponent {

  list: String[];
}

在所有 ngFors 上出现错误

<ul >
  <li *ngFor="let thing of list">
        <p>{{thing}}</p>
  </li>
</ul>

【问题讨论】:

  • 你使用的是哪个 Angular2 版本?

标签: html typescript angular


【解决方案1】:

删除

 directives: [FORM_DIRECTIVES, CORE_DIRECTIVES]

在您显然正在使用的 Angular2 beta 中使用 # 而不是 let

【讨论】:

  • 感谢您的帮助!我想这就是你不阅读更改日志时会发生的情况:^)
猜你喜欢
  • 2020-10-24
  • 2016-05-15
  • 2016-11-13
  • 2016-03-04
  • 2017-06-21
  • 2017-02-03
  • 2017-02-27
  • 1970-01-01
相关资源
最近更新 更多