簡體   English   中英

Angular4 angularfire2

[英]Angular4 angularfire2

我正在使用angular4項目,因為我無法進行編譯,因為遇到了有關angularfire2的錯誤。 有人可以幫我。

ERROR in node_modules/angularfire2/firebase.app.module.d.ts(5,45): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firebase.app.module.d.ts(8,17): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firebase.app.module.d.ts(9,21): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firebase.app.module.d.ts(10,22): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firebase.app.module.d.ts(11,20): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firebase.app.module.d.ts(13,22): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/changes.d.ts(8,43): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/changes.d.ts(9,46): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/changes.d.ts(9,80): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/changes.d.ts(10,49): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/changes.d.ts(10,95): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/changes.d.ts(10,140): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/changes.d.ts(10,182): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/changes.d.ts(11,49): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/changes.d.ts(11,94): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/changes.d.ts(11,130): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/collection.d.ts(8,54): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/collection.d.ts(8,96): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/collection.d.ts(10,19): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/collection.d.ts(12,22): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/collection.d.ts(12,69): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/collection.d.ts(13,27): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/collection.d.ts(14,25): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/collection.d.ts(15,30): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/collection.d.ts(16,27): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/collection.d.ts(17,27): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/document/document.d.ts(8,10): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/document/document.d.ts(9,22): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/document/document.d.ts(10,28): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/document/document.d.ts(14,42): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/firestore.d.ts(9,55): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/firestore.d.ts(12,25): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/interfaces.d.ts(4,11): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/interfaces.d.ts(5,14): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/interfaces.d.ts(14,37): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/interfaces.d.ts(14,80): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/interfaces.d.ts(16,10): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/interfaces.d.ts(17,12): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/observable/fromRef.d.ts(6,41): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/observable/fromRef.d.ts(6,80): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/observable/fromRef.d.ts(7,41): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/observable/fromRef.d.ts(7,98): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/observable/fromRef.d.ts(8,48): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/observable/fromRef.d.ts(8,93): error TS2503: Cannot find namespace 'firebase'.

ERROR in node_modules/angularfire2/firebase.app.module.d.ts(5,45): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firebase.app.module.d.ts(8,17): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firebase.app.module.d.ts(9,21): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firebase.app.module.d.ts(10,22): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firebase.app.module.d.ts(11,20): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firebase.app.module.d.ts(13,22): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/changes.d.ts(8,43): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/changes.d.ts(9,46): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/changes.d.ts(9,80): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/changes.d.ts(10,49): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/changes.d.ts(10,95): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/changes.d.ts(10,140): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/changes.d.ts(10,182): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/changes.d.ts(11,49): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/changes.d.ts(11,94): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/changes.d.ts(11,130): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/collection.d.ts(8,54): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/collection.d.ts(8,96): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/collection.d.ts(10,19): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/collection.d.ts(12,22): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/collection.d.ts(12,69): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/collection.d.ts(13,27): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/collection.d.ts(14,25): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/collection.d.ts(15,30): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/collection.d.ts(16,27): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/collection/collection.d.ts(17,27): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/document/document.d.ts(8,10): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/document/document.d.ts(9,22): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/document/document.d.ts(10,28): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/document/document.d.ts(14,42): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/firestore.d.ts(9,55): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/firestore.d.ts(12,25): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/interfaces.d.ts(4,11): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/interfaces.d.ts(5,14): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/interfaces.d.ts(14,37): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/interfaces.d.ts(14,80): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/interfaces.d.ts(16,10): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/interfaces.d.ts(17,12): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/observable/fromRef.d.ts(6,41): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/observable/fromRef.d.ts(6,80): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/observable/fromRef.d.ts(7,41): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/observable/fromRef.d.ts(7,98): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/observable/fromRef.d.ts(8,48): error TS2503: Cannot find namespace 'firebase'.
node_modules/angularfire2/firestore/observable/fromRef.d.ts(8,93): error TS2503: Cannot find namespace 'firebase'.

如果您的版本4.8.1,請返回firebase 4.8.0:

  1. 在package.json中,從“firebase”中刪除^:“^ 4.8.1”。 然后通過將4.8.1更改為4.8.0將Firebase從4.8.1降級到4.8.0。 最終結果應如下所示:“firebase”:“4.8.0”。
  2. 在項目根目錄中運行npm update。 NPM將為您降級Firebase。
  3. 運行ng serve --open以檢查編譯錯誤。 應該沒有。
  4. 請享用!

要安裝角度為4的angularfire2:

  1. npm install angularfire2 firebase --save
  2. 將以下代碼復制到environment.ts文件中
export const environment = {
production: false,
firebase: {
apiKey: 'xxx',
authDomain: 'xxx.firebaseapp.com',
databaseURL: 'https://xxx.firebaseio.com',
projectId: 'xxx',
storageBucket: 'xxx.appspot.com',
messagingSenderId: 'xxx'
}
};
  1. 從angularfire2和環境導入AngularFireModule,AngularFireDatabaseModule和AngularFireAuthModule以獲取Firebase設置。
import { AngularFireModule } from 'angularfire2';
import { AngularFireDatabaseModule } from 'angularfire2/database';
import { AngularFireAuthModule } from 'angularfire2/auth';
import { environment } from 'environments/environment';
  1. 然后在NgModule中添加模塊。 可以使用“initialiazeApp”自定義Firebase名稱
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AngularFireModule.initializeApp(environment.firebase, 'letslearn-dev'),
AngularFireDatabaseModule,
AngularFireAuthModule
],
bootstrap: [AppComponent]
})
export class AppModule { }
  1. 創建AuthService以管理身份驗證
import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase/app';
import { Observable } from 'rxjs/Observable';
export class AuthService {
private authState: Observable<firebase.User>
private currentUser: firebase.User = null;
constructor(public afAuth: AngularFireAuth) {
this.authState = this.afAuth.authState;
this.authState.subscribe(user => {
  if (user) {
    this.currentUser = user;
  } else {
    this.currentUser = null;
  }
});
}
getAuthState() {
return this.authState;
}
}
  1. 在您的應用組件中注入Firebase Auth服務。
import { AuthService } from './shared/auth.service';
export class AppComponent implements OnInit {
user = null;
constructor(
private auth: AuthService) { }
ngOnInit() {
this.auth.getAuthState().subscribe(
  (user) => this.user = user);
}
}

希望這能解決你的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM