是否可以将angularfire2与Angular 6一起使用?

时间:2018-04-28 11:29:54

标签: angular firebase angularfire2 angular6

我试图为我的Angular 6应用添加firebase支持但是在添加angularfire2时

npm install angularfire2 firebase

我得到很多警告说我必须使用Angular 5.例如

npm WARN angularfire2@5.0.0-rc.6.0 requires a peer of @angular/core@^5.0.0 but none is installed. You must install peer dependencies yourself.

今天是否可以将angularfire2与Angular 6一起使用?

编译时出现此错误:

ERROR in node_modules/angularfire2/angularfire2.d.ts(3,10): error TS2305: Module '"/home/rrr/Projects/ng6test/node_modules/rxjs/Subscription"' has no exported member 'Subscription'.
node_modules/angularfire2/firebase.app.module.d.ts(10,22): error TS2720: Class 'FirebaseApp' incorrectly implements class 'FirebaseApp'. Did you mean to extend 'FirebaseApp' and inherit its members as a subclass?
  Property 'automaticDataCollectionEnabled' is missing in type 'FirebaseApp'.
node_modules/rxjs/Subscription.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat/Subscription'.

我尝试安装rxjs-compat,但之后又收到了警告

ERROR in node_modules/angularfire2/firebase.app.module.d.ts(10,22): error TS2720: Class 'FirebaseApp' incorrectly implements class 'FirebaseApp'. Did you mean to extend 'FirebaseApp' and inherit its members as a subclass?
  Property 'automaticDataCollectionEnabled' is missing in type 'FirebaseApp'.

3 个答案:

答案 0 :(得分:4)

我试过,我不能让Angular 6适用于任何版本的AngularFire2(最新版本:5.0.0-rc.7.2-next)。我想我们需要等待AngularFire2的下一个主要版本。

更新:
临时解决方案是安装rxjs-compat npm install --save rxjs-compat

答案 1 :(得分:1)

尝试:

npm install firebase angularfire2@next --save

已在预发布版本中修复:

angularfire2@next

答案 2 :(得分:0)

的package.json

"dependencies": 
{
"@angular/animations": "^6.0.3",
"@angular/cdk": "^6.1.0",
"@angular/common": "^6.0.3",
"@angular/compiler": "^6.0.3",
"@angular/core": "^6.0.3",
"@angular/forms": "^6.0.3",
"@angular/http": "^6.0.3",
"@angular/material": "^6.1.0",
"@angular/platform-browser": "^6.0.3",
"@angular/platform-browser-dynamic": "^6.0.3",
"@angular/router": "^6.0.3",
"@firebase/app": "^0.3.3",
"angularfire2": "^5.0.0-rc.10",
"core-js": "^2.5.6",
"firebase": "^5.0.3",
"hammerjs": "^2.0.8",
"rxjs": "^6.2.0",
"rxjs-compat": "^6.2.0",
"zone.js": "^0.8.26"
}

app.module.ts

import { AngularFireModule } from 'angularfire2';
import { AngularFireDatabaseModule } from 'angularfire2/database';
import { AngularFireAuthModule } from 'angularfire2/auth';
import { environment } from '../environments/environment';

@ngModule

@NgModule({
    declarations: [
        AppComponent
    ],
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        routing,
        FormsModule,
        HttpClientModule,
        AngularFireModule.initializeApp(environment.firebase),
        AngularFireDatabaseModule,
        AngularFireAuthModule

    ]
})

环境

firebase: {
    apiKey: "apikey",
    authDomain: "authDomain",
    databaseURL: "https://projectId.firebaseio.com",
    projectId: "projectId",
    storageBucket: "projectId.appspot.com",
    messagingSenderId: "messagingSenderId"
  }