“Can't bind to 'ngFor' since it isn

2019-09-14 15:42发布

问题:

Can't tell what I'm doing wrong here. Tried explicity defining the ngFor directive through CORE_DIRECTIVES, and using let. Is there something I missed?

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[];
}

Getting an error on all ngFors

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

回答1:

remove

 directives: [FORM_DIRECTIVES, CORE_DIRECTIVES]

use # instead of let in Angular2 beta that you're obviously using.