Angular 属性 '$ref' 在类型 'AngularFireList<{}> 中缺失

Angular Property '$ref' is missing in type 'AngularFireList<{}>

我遇到了这个错误

/Users/macmini/Desktop/newap/src/app/component/content/content.component.ts (18,5): Type 'AngularFireList<{}>' is not assignable to type 'FirebaseListObservable'.

Property '$ref' is missing in type 'AngularFireList<{}>'.

component.ts

import { Component, OnInit } from '@angular/core';
import {Subscription} from 'rxjs';

import {AngularFireDatabase } from 'angularfire2/database';
import {FirebaseListObservable} from 'angularfire2/database-deprecated';

@Component({
  selector: 'app-content',
  templateUrl: './content.component.html',
  styleUrls: ['./content.component.css']
})

export class ContentComponent implements OnInit {

  courses$:FirebaseListObservable<any[]>;

  constructor(db:AngularFireDatabase){
    this.courses$ = db.list('/courses');

  }

  ngOnInit() {

  }

}

component.html

<ul *ngFor="let item of (courses$ | async)">
  <li><a href="#">{{item.$value}}</a>

  </li>
</ul>

应用模式

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import {AngularFireModule} from 'angularfire2'
import {AngularFireDatabaseModule} from 'angularfire2/database'
import {environment} from '../environments/environment';

import { AppComponent } from './app.component';
import { ContentComponent } from './component/content/content.component';




@NgModule({
  declarations: [
    AppComponent,
    ContentComponent,

  ],
  imports: [
    BrowserModule,
    AngularFireModule.initializeApp(environment.firebase),
    AngularFireDatabaseModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

package.ison

{
  "name": "newap",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^4.0.0",
    "@angular/common": "^4.0.0",
    "@angular/compiler": "^4.0.0",
    "@angular/core": "^4.0.0",
    "@angular/forms": "^4.0.0",
    "@angular/http": "^4.0.0",
    "@angular/platform-browser": "^4.0.0",
    "@angular/platform-browser-dynamic": "^4.0.0",
    "@angular/router": "^4.0.0",
    "angularfire2": "^5.0.0-rc.3",
    "core-js": "^2.4.1",
    "firebase": "^4.7.0",
    "rxjs": "^5.0.1",
    "xjs": "^0.1.6",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "@angular/cli": "1.1.0",
    "@angular/compiler-cli": "^4.0.0",
    "@angular/language-service": "^4.0.0",
    "@types/jasmine": "2.5.45",
    "@types/node": "~6.0.60",
    "angular2": "^2.0.0-beta.21",
    "codelyzer": "~3.0.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.0.4",
    "tslint": "~5.3.2",
    "typescript": "~2.3.3"
  }
}

我使用版本 angular 和 nodejs @angular/cli:1.1.0 节点:8.11.2 os:达尔文 x64

我认为问题与您使用的是一种已弃用的访问列表数据的方法有关。参考访问列表this link for the relevant Angularfire2 documentation

它提供了这个不使用 FirebaseListObservable 的示例:

import { Component } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
import { Observable } from 'rxjs';

@Component({
  selector: 'app-root',
  template: `
  <ul>
    <li *ngFor="let item of items | async">
       {{ item | json }}
    </li>
  </ul>
  `,
})
export class AppComponent {
  items: Observable<any[]>;

  constructor(db: AngularFireDatabase) {
    this.items = db.list('items').valueChanges();
  }

}