2
我已經拉過這段頭髮很長一段時間了。IONIC 2 RefrenceError:firebase沒有定義
我正在嘗試使用Facebook身份驗證的Firebase。我也初始化我的應用程序在app.module.ts 但是,當我在我的Android設備上運行下述代碼,我得到
"RefrenceError: firebase is not defined"
signInWithFacebook(){
var _authInfo
Facebook.login(['email'])
.then((_response) => {
console.log(_response)
_authInfo = _response
return this._FBUserProfile();
}).then((success) => {
this.TEST = "IM IN";
let creds = (firebase.auth.FacebookAuthProvider as any).credential(_authInfo.authResponse.accessToken)
let providerConfig = {
provider: AuthProviders.Facebook,
method: AuthMethods.OAuthToken,
remember: 'default',
scope: ['email'],
};
this.af.auth.login(creds, providerConfig)
.then((success) => {
console.log("Firebase success: " + JSON.stringify(success));
this. Error += (JSON.stringify(success));
this.UID = success.auth.uid;
})
.catch((error) => {
console.log("Firebase failure: " + JSON.stringify(error));
this. Error += (JSON.stringify(error))
});
})
.catch((_error) => { this. Error +=(_error) }) //Error caught here.
}
_FBUserProfile() {
return new Promise((resolve, reject) => {
Facebook.api('me?fields=id,name,email,first_name,last_name,picture.width(100).height(100).as(picture_small),picture.width(720).height(720).as(picture_large)', [])
.then((profileData) => {
console.log(JSON.stringify(profileData));
return resolve(profileData);
}, (err) => {
console.log(JSON.stringify(err));
return reject(err);
});
});
}
這些是我的進口。我已經在項目文件夾中運行npm install firebase angularfire2 --save
import { Injectable } from '@angular/core';
import { AuthProviders, AngularFireAuth, FirebaseAuthState, AuthMethods, AngularFire } from 'angularfire2';
import { Platform } from 'ionic-angular';
import { Facebook } from 'ionic-native';
另外,還要注意