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

后端 未结 13 1654
耶瑟儿~
耶瑟儿~ 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:10

    I forgot to annotate my component with "@Input" (Doh!)

    book-list.component.html (Offending code):

      <-- Can't bind to 'book' since it isn't a known property of 'app-book-item'
    
    

    Corrected version of book-item.component.ts:

    import { Component, OnInit, Input } from '@angular/core';
    
    import { Book } from '../model/book';
    import { BookService } from '../services/book.service';
    
    @Component({
      selector: 'app-book-item',
      templateUrl: './book-item.component.html',
      styleUrls: ['./book-item.component.css']
    })
    export class BookItemComponent implements OnInit {
    
      @Input()
      public book: Book;
    
      constructor(private bookService: BookService)  { }
    
      ngOnInit() {}
    
    }
    

提交回复
热议问题