angularfire 2:错误“未处理的承诺拒绝:TypeError:无法读取属性” [英] angularfire 2: Error "Unhandled Promise rejection: TypeError: Cannot read property"

查看:691
本文介绍了angularfire 2:错误“未处理的承诺拒绝:TypeError:无法读取属性”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了一个示例应用程序连接到Firebase

在我的Main.ts中,我写了这个:

 从'@ angular / platform-b​​rowser-dynamic'导入{bootstrap}; 
从'@ angular / core'导入{enableProdMode};
从'./app/'导入{AppComponent,environment};
从'angularfire2'导入{FIREBASE_PROVIDERS,defaultFirebase,firebaseAuthConfig,AuthProviders,AuthMethods};

if(environment.production){
enableProdMode();


ootstrap(AppComponent,[
FIREBASE_PROVIDERS,
defaultFirebase({
apiKey:MYKEY,
authDomain:MYDOMAIN。 firebaseapp.com,
databaseURL:https://MYDOMAN.firebaseio.com,
storageBucket:MYDOMAIN.appspot.com,
}),
firebaseAuthConfig( {
provider:AuthProviders.Password,
method:AuthMethods.Popup
})
]);

编辑:这里是component.ts

 从'@ angular / core'导入{Component}; 
从'./login/'

@Component({
moduleId:module.id,
selector:'app-root',
templateUrl:'app.component.html',
styleUrls:['app.component.css'],
directives:[LoginComponent]
})
export class AppComponent {
title ='请登录到应用程序';
}

但是,当启动我的应用程序ng serve并调用URL时,我得到一个错误:

lockquote
zone.js:461未处理的Promise拒绝TypeError:无法读取
属性'FacebookAuthProvider' undefined
在Object.eval( http:// localhost:4200 /vendor/angularfire2/providers/firebase_sdk_auth_backend.js:24:43 )在eval( http:// localhost:4200 / vendor / angularfire2 / providers / firebase_sdk_auth_backend.js:108:4
at eval( http:// localhost:4200 / vendor / angularfire2 / providers / firebase_sdk_auth_backend.js:109:3
在Object.eval( http:// localhost:4200 / vendor / angularfire2 / angularfire2.js:33: a>)
评估
http:// localhost:4200 / vendor /angularfire2/providers/firebase_sdk_auth_backend.js
评估 http:// localhost: 4200 / vendor / angularfire2 / angularfire2.js
评估 http:/ /localhost:4200/app/login/login.component.js
评估 http:// localhost:4200 / app / login / index.js 评估
http:// localhost:4200 / app / app.component.js 评估
http:// localhost:4200 / app / index.js 评估
http:// localhost:4200 / main.js 错误加载
http:// localhost:4200 / main.js ;区域:;任务:承诺。
Value:Error:TypeError:Can not read property'FacebookAuthProvider'
of undefined(...)


根据评论,使用Firebase 2.x SDK代替Firebase 3时出现此错误。 .x SDK是AngularFire2所必需的。


I tried an example app to connect to Firebase

In my Main.ts I wrote this:

import { bootstrap } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppComponent, environment } from './app/';
import { FIREBASE_PROVIDERS, defaultFirebase, firebaseAuthConfig, AuthProviders, AuthMethods } from 'angularfire2';

if (environment.production) {
  enableProdMode();
}

bootstrap(AppComponent,[
  FIREBASE_PROVIDERS,
  defaultFirebase({
    apiKey: "MYKEY",
    authDomain: "MYDOMAIN.firebaseapp.com",
    databaseURL: "https://MYDOMAN.firebaseio.com",
    storageBucket: "MYDOMAIN.appspot.com",
  }),
  firebaseAuthConfig({
    provider: AuthProviders.Password,
    method: AuthMethods.Popup
  })
]);

EDIT: here is the component.ts

import { Component } from '@angular/core';
import { LoginComponent } from './login/'

@Component({
  moduleId: module.id,
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.css'],
  directives: [ LoginComponent ]
})
export class AppComponent {
  title = 'Please Login to the App';
}

But when is start my App with "ng serve" and call the URL , I get an error called:

zone.js:461 Unhandled Promise rejection: TypeError: Cannot read property 'FacebookAuthProvider' of undefined at Object.eval (http://localhost:4200/vendor/angularfire2/providers/firebase_sdk_auth_backend.js:24:43) at eval (http://localhost:4200/vendor/angularfire2/providers/firebase_sdk_auth_backend.js:108:4) at eval (http://localhost:4200/vendor/angularfire2/providers/firebase_sdk_auth_backend.js:109:3) at Object.eval (http://localhost:4200/vendor/angularfire2/angularfire2.js:33:35) Evaluating http://localhost:4200/vendor/angularfire2/providers/firebase_sdk_auth_backend.js Evaluating http://localhost:4200/vendor/angularfire2/angularfire2.js Evaluating http://localhost:4200/app/login/login.component.js Evaluating http://localhost:4200/app/login/index.js Evaluating http://localhost:4200/app/app.component.js Evaluating http://localhost:4200/app/index.js Evaluating http://localhost:4200/main.js Error loading http://localhost:4200/main.js ; Zone: ; Task: Promise.then ; Value: Error: TypeError: Cannot read property 'FacebookAuthProvider' of undefined(…)

Any ideas?

解决方案

Based on the comments, it appears that this error occurs when using the Firebase 2.x SDK instead of the Firebase 3.x SDK which is required by AngularFire2.

这篇关于angularfire 2:错误“未处理的承诺拒绝:TypeError:无法读取属性”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆