Search code examples
javascriptangularfirebaseangular2-services

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


i got this error

/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>

app-modal

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"
  }
}

i use version angular and nodejs @angular/cli: 1.1.0 node: 8.11.2 os: darwin x64


Solution

  • I believe the problem is related to the fact that you're using a deprecated method of accessing list data. Refer to this link for the relevant Angularfire2 documentation on accessing lists.

    It provides this example that doesn't use a 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();
      }
    
    }