Exception: Can't bind to 'ngFor' since it isn't a known native property

后端 未结 13 1531
耶瑟儿~
耶瑟儿~ 2020-12-12 16:35

What am I doing wrong?

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

@Component({
  selector: \'conf-talks\',
  template: `
相关标签:
13条回答
  • 2020-12-12 17:23

    This Statement used in Angular2 Beta version.....

    Hereafter use let instead of #

    let keyword is used to declare local variable

    0 讨论(0)
  • 2020-12-12 17:23

    You should use let keyword as to declare local variables e.g *ngFor="let talk of talks"

    0 讨论(0)
  • 2020-12-12 17:24

    Also don't try to use pure TypeScript in this... I wanted to more correspond to for usage and use *ngFor="const filter of filters" and got the ngFor not a known property error. Just replacing const by let is working.

    As @alexander-abakumov said for the of replaced by in.

    0 讨论(0)
  • 2020-12-12 17:27

    Use this

    <div *ngFor="let talk of talks> 
       {{talk.title}} 
       {{talk.speaker}}
       <p>{{talk.description}} 
    </div>
    

    You need to specify variable to iterate over an array of an object

    0 讨论(0)
  • 2020-12-12 17:35

    Another typo leading to the OP's error could be using in:

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

    You should use of instead:

    <div *ngFor="let talk of talks">
    
    0 讨论(0)
  • 2020-12-12 17:36

    In my case I made the mistake of copying *ng-for= from the docs.

    https://angular.io/guide/user-input

    Correct me if I am wrong. But it seems *ng-for= has been changed to *ngFor=

    0 讨论(0)
提交回复
热议问题