如何获取对Firebase实时数据库的引用

时间:2018-06-06 01:44:30

标签: firebase firebase-realtime-database angularfire2

当我尝试在angularfire2应用程序上使用rtdb时,我收到此错误。

ERROR TypeError: firebase_app__WEBPACK_IMPORTED_MODULE_2__.database is not a function
    at new AuthService (auth.service.ts:29)
    at _createClass (core.js:9272)
    at _createProviderInstance$1 (core.js:9234)
    at resolveNgModuleDep (core.js:9200)
    at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (core.js:9911)
    at resolveDep (core.js:10276)
    at createClass (core.js:10152)
    at createDirectiveInstance (core.js:10033)
    at createViewNodes (core.js:11255)
    at callViewAction (core.js:11571)

我按如下方式导入了firebase:

import * as firebase from 'firebase/app';

以下给出了上述错误:

db = firebase.database();

2 个答案:

答案 0 :(得分:0)

像这样导入:

import * as firebase from 'firebase';
import 'firebase/firestore';

答案 1 :(得分:0)

使用AngularFire2,可以通过npm

进行确认