我是 Angular 和 FireBase 的新手,我在Udemy的课程后遇到了这个问题。
教师使用 AngularFire 项目实现此类,以在Firebase数据库上执行示例查询:
import { Component } from '@angular/core';
import {FirebaseListObservable} from 'angularfire2/database-deprecated';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';
constructor(private af: AngularFire) {
const courses$: FirebaseListObservable<any> = af.database.list('courses'); // It is an Observable ($)
courses$.subscribe(
val => console.log(val)
);
}
}
问题是我无法导入用作构造函数输入参数的 AngularFire 类型,我无法理解为什么(将鼠标光标放在此类型上我是没有获得将此类型导入导入列表的选择。)
可能是什么问题?我应该安装 AngualarFire依赖项),这是我的** package.json 依赖配置文件的内容:
{
"name": "final-project",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^5.0.0",
"@angular/common": "^5.0.0",
"@angular/compiler": "^5.0.0",
"@angular/core": "^5.0.0",
"@angular/forms": "^5.0.0",
"@angular/http": "^5.0.0",
"@angular/platform-browser": "^5.0.0",
"@angular/platform-browser-dynamic": "^5.0.0",
"@angular/router": "^5.0.0",
"angularfire2": "^5.0.0-rc.4",
"core-js": "^2.4.1",
"firebase": "4.8.0",
"rxjs": "^5.5.2",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "1.6.3",
"@angular/compiler-cli": "^5.0.0",
"@angular/language-service": "^5.0.0",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "^4.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.2.0",
"tslint": "~5.7.0",
"typescript": "~2.4.2"
}
}
可能是什么问题?我错过了什么?我该如何解决这个问题?
答案 0 :(得分:0)
你需要查看Angular Fire repo的自述文件
import { AngularFireDatabase} from 'angularfire2/database';
选中link
。
此外,对于旧版本的Angular Fire,您可以在Rc 4.0.0.2
下面尝试此操作。
import {AngularFireDatabase} from "angularfire2/database/database";
constructor(private af: AngularFireDatabase) { }