typescript 从“angularfire2/database”导入 { AngularFireDatabase, FirebaseListObservable };

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46651154/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 04:57:29  来源:igfitidea点击:

import { AngularFireDatabase, FirebaseListObservable } from "angularfire2/database";

angulartypescriptfirebasefirebase-realtime-databaseangularfire2

提问by asli

i had problem to

我有问题

import { AngularFireDatabase, FirebaseListObservable } from "angularfire2/database";

i imported AngularFireDatabase but FirebaseListObservable was under a red line after searching this post helped me resolve my problem Getting an error: "Has no exported member AngularFire, AuthProviders, AUthMethods, FirebaseListObservable" in AngularFire2?

我导入了 AngularFireDatabase,但在搜索这篇文章后,FirebaseListObservable 位于红线下帮助我解决了我的问题 收到错误:“AngularFire2 中没有导出成员 AngularFire、AuthProviders、AUthMethods、FirebaseListObservable”?

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

but when i compile i get and it cant help i dont know what to do where searching ect core.es5.js:1020 ERROR Error: Uncaught (in promise): Error: No provider for AngularFireDatabase! Error: No provider for AngularFireDatabase!

但是当我编译时我得到了它并不能帮助我不知道在搜索 ect core.es5.js:1020 错误错误:未捕获(承诺):错误:没有 AngularFireDatabase 的提供者!错误:没有 AngularFireDatabase 的提供者!

"angularfire2": "^5.0.0-rc.2", "core-js": "^2.4.1", "firebase": "^4.5.0",

"angularfire2": "^5.0.0-rc.2", "core-js": "^2.4.1", "firebase": "^4.5.0",

回答by asli

i got the answer after reading https://github.com/angular/angularfire2/blob/master/CHANGELOG.md5.0.0-rc.0 (2017-10-03)

我在阅读https://github.com/angular/angularfire2/blob/master/CHANGELOG.md5.0.0-rc.0 (2017-10-03)后得到了答案

the -deprecated allows you to use the old database API

-deprecated 允许您使用旧的数据库 API

import { AngularFireDatabaseModule } from 'angularfire2/database-deprecated';

in the app.module.js and in your service you use

在 app.module.js 和您使用的服务中

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

thank you both of you, you helped me

谢谢你们,你们帮助了我

回答by S.Adikaram

In angularfire2": "^5.0.0-rc.2 you can't use FirebaseListObservable instead you will have to use

在 angularfire2": "^5.0.0-rc.2 你不能使用 FirebaseListObservable 而你必须使用

import { AngularFireDatabase } from 'angularfire2/database';

and use it like this

并像这样使用它

constructor(public af: AngularFireDatabase) {
  let restaurants = this.af.list('/path');
}

回答by Sajeetharan

You need to import the following and add it under your app.module.ts

您需要导入以下内容并将其添加到您的 app.module.ts 下

import { AngularFireModule } from 'angularfire2';
import { AngularFireDatabaseModule } from 'angularfire2/database';


@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AngularFireModule.initializeApp(firebaseConfig),
    AngularFireDatabaseModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

回答by Ahmed fathy

You can't use FirebaseListObservable in current version of angularfire2.
It worked in old version of angularfire2 like 4.0.0-rc.1.

您不能在当前版本的 angularfire2 中使用 FirebaseListObservable。
它适用于旧版本的 angularfire2,如 4.0.0-rc.1。

So, install it and it will work totally fine (in terminal):

因此,安装它,它将完全正常工作(在终端中):

npm i [email protected]

npm i [email protected]

and import:

并导入:

import {AngularFireDatabase,FirebaseListObservable} from 'angularfire2/database';

import { AngularFireAuthModule, AngularFireAuth } from 'angularfire2/auth';