尝试修复旧代码,但出现错误,无法正确命名“书”。我对此很陌生,因此可以提供任何帮助。是否应该以某种方式涉及课堂教学? src / app / app.component.ts(31,27)中发生错误:错误TS2304:找不到名称“书”。
import { Component } from '@angular/core';
import { AngularFireDatabase, AngularFireList } from '@angular/fire/database';
@Component({
selector: 'app-root',
template: `
<ul>
<li *ngFor="let book of books | async">
<pre>{{ book | json }}</pre>
</li>
</ul>
<button (click)="addBook()">Add a book!</button>
<button (click)="filterBooks()">Filter books</button>
`
})
export class AppComponent {
public books: AngularFireList<any[]>;
private bookCounter = 0;
private filter = '';
constructor(public title, private af: AngularFireDatabase) {
this.books = af.list('/books');
}
public addBook(): void {
const newBook = new book(`My book #${this.bookCounter++}`);
this.books.push(newBook);
}
public filterBooks(): void {
this.books = this.af.list('/books', ref =>
ref.orderByChild('title').equalTo('My book #1'));
}
}
答案 0 :(得分:0)
好像您正在尝试实例化一本书类:
const newBook = new book(`My book #${this.bookCounter++}`);
但是您尚未导入book类,因此只需导入它,它应该可以解决您的错误。