不会将参数带到另一个屏幕。
我试图获得姓名和电子邮件,但它没有运行,所以登录运行我完美。
我希望他们能帮我
离子版本如下:
cli包:(C:\node\Ionic\taxilurin\node_modules)
@ionic/cli-plugin-cordova : 1.6.2
@ionic/cli-plugin-ionic-angular : 1.4.1
@ionic/cli-utils : 1.7.0
ionic (Ionic CLI) : 3.7.0全球一揽子计划:
Cordova CLI : 7.0.1本地套餐:
@ionic/app-scripts : 2.1.3
Cordova Platforms : android 6.2.3 browser 4.1.0
Ionic Framework : ionic-angular 3.6.0系统:
Node : v6.11.2
OS : Windows 10
npm : 3.10.10我的密码主页-登录:
import { Component } from '@angular/core';
//Importamos los elementos que vamos a utlizar
import { RegistroCPage } from './../RegistroCorpotativo/registroC';
import { RegistroPPage } from './../registroParticular/registroP';
import { RegistroNPage } from './../registroNuevo/registroN';
import { NativeStorage } from '@ionic-native/native-storage';
import { Facebook } from '@ionic-native/facebook';
import { NavController } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
registroCPage = RegistroCPage;
registroPPage = RegistroPPage;
registroNPage = RegistroNPage;
constructor(
private facebook: Facebook,
public navCtrl: NavController,
public nativeStorage: NativeStorage
) {
}
loginFacebook() {
this.facebook.login(['public_profile', 'email'])
.then(rta => {
console.log(rta.status);
if (rta.status == 'connected') {
this.getInfo();
};
})
.catch(error => {
console.error(error);
});
}
getInfo() {
let nav = this.navCtrl;
let env = this;
this.facebook.api('/me?fields=id,name,email,first_name,picture,last_name,gender', ['public_profile', 'email'])
.then(function (user) {
env.nativeStorage.setItem('user',
{
name: user.name,
gender: user.gender,
picture: user.picture
})
.then(function () {
nav.push(RegistroNPage);
}, function (error) {
console.log(error);
})
})
.catch(error => {
console.error(error);
});
}
}我的代码de PostLogen:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { NativeStorage } from '@ionic-native/native-storage';
import { Facebook } from '@ionic-native/facebook';
import { HomePage } from './../home/home';
@Component({
selector: 'page-registroN',
templateUrl: 'registroN.html'
})
export class RegistroNPage {
user: any;
userReady: boolean = false;
constructor(
public navCtrl: NavController,
public fb: Facebook,
public nativeStorage: NativeStorage) {
}
ionViewCanEnter() {
let env = this;
this.nativeStorage.getItem('user')
.then(function (data) {
env.user = {
name: data.name,
gender: data.gender,
email: data.email,
picture: data.picture
};
env.userReady = true;
}, function (error) {
console.log(error);
});
}
doFbLogout() {
var nav = this.navCtrl;
let env = this;
this.fb.logout()
.then(function (response) {
//user logged out so we will remove him from the NativeStorage
env.nativeStorage.remove('user');
nav.push(HomePage);
}, function (error) {
console.log(error);
});
}
}

发布于 2017-08-11 09:50:55
ionViewCanEnter()方法评估路由器是否应该将页面推入导航堆栈。此方法应返回一个布尔值(或布尔值的允诺)来执行此计算。
您实际上没有返回一个值,因此该函数正在返回undefined,计算结果始终为false,因此无法输入页面。
对代码进行以下小的更改,以返回适当的值:
ionViewCanEnter() {
let env = this;
return this.nativeStorage.getItem('user')
.then(function (data) {
env.user = {
name: data.name,
gender: data.gender,
email: data.email,
picture: data.picture
};
env.userReady = true;
return true;
}, function (error) {
console.log(error);
return false;
});
}https://stackoverflow.com/questions/45617377
复制相似问题