Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/411.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在Ionic构造函数中调用变量返回未定义的_Javascript_Cordova_Variables_Ionic Framework_Constructor - Fatal编程技术网

Javascript 在Ionic构造函数中调用变量返回未定义的

Javascript 在Ionic构造函数中调用变量返回未定义的,javascript,cordova,variables,ionic-framework,constructor,Javascript,Cordova,Variables,Ionic Framework,Constructor,如何在构造函数中调用变量 constructor ( private auth: AngularFireAuth ) { this.auth.authState.subscribe((user)=> {this.email = user.email}); this.url = 'http://localhost/check.php' + this.email; // NOW CALLIG this.email RETURN UNDEFINED. HOW CAN I MAKE IT W

如何在构造函数中调用变量

constructor ( private auth: AngularFireAuth ) {
this.auth.authState.subscribe((user)=> {this.email = user.email});

this.url = 'http://localhost/check.php' + this.email;  
// NOW CALLIG this.email RETURN UNDEFINED. HOW CAN I MAKE IT WORK?
..........
..........
}

由于不可避免的原因,我无法添加
http://localhost/check.php“+此电子邮件
{this.email=user.email;

之后,您可以尝试在页面事件的不同阶段触发哪个。

可能是您可以尝试在页面事件的不同阶段触发哪个。

您也可以在订阅者中进行调用。或者在您不知道设置了变量的情况下从内部调用函数

constructor ( private auth: AngularFireAuth ) {
this.auth.authState.subscribe((user)=> {
this.email = user.email;
this.url = 'http://localhost/check.php' + this.email; 
// NOW CALLIG this.email
})
}
//编辑

constructor ( private auth: AngularFireAuth ) {
    this.auth.authState.subscribe((user)=> {
    checkEmail(user.email).then((valid) => 
    {
        if(valid) {
            this.email = user.email
            this.url = 'http://localhost/check.php' + this.email; 
        }
    }
})
}

checkEmail(email: string): Promise<boolean>
{
    let valid = false;
    //email valid? -> verify the email is valid, if yes return true

    return valid;

}
构造函数(私有身份验证:AngularFireAuth){
this.auth.authState.subscribe((用户)=>{
检查电子邮件(user.email)。然后((有效)=>
{
如果(有效){
this.email=user.email
this.url=http://localhost/check.php“+此电子邮件;
}
}
})
}
checkEmail(email:string):承诺
{
设有效=假;
//电子邮件是否有效?->验证电子邮件是否有效,如果是,返回true
返回有效;
}

->未测试

您也可以在订阅服务器中进行调用。或者在您知道变量已设置的情况下从内部调用函数

constructor ( private auth: AngularFireAuth ) {
this.auth.authState.subscribe((user)=> {
this.email = user.email;
this.url = 'http://localhost/check.php' + this.email; 
// NOW CALLIG this.email
})
}
//编辑

constructor ( private auth: AngularFireAuth ) {
    this.auth.authState.subscribe((user)=> {
    checkEmail(user.email).then((valid) => 
    {
        if(valid) {
            this.email = user.email
            this.url = 'http://localhost/check.php' + this.email; 
        }
    }
})
}

checkEmail(email: string): Promise<boolean>
{
    let valid = false;
    //email valid? -> verify the email is valid, if yes return true

    return valid;

}
构造函数(私有身份验证:AngularFireAuth){
this.auth.authState.subscribe((用户)=>{
检查电子邮件(user.email)。然后((有效)=>
{
如果(有效){
this.email=user.email
this.url=http://localhost/check.php“+此电子邮件;
}
}
})
}
checkEmail(email:string):承诺
{
设有效=假;
//电子邮件是否有效?->验证电子邮件是否有效,如果是,返回true
返回有效;
}

->未测试

不可能…可观察项是异步的..您的
this.url
分配发生在调用订阅函数之前不可能…可观察项是异步的..您的
this.url
分配发生在调用订阅函数之前如果我调用另一个externa,安全漏洞将打开
//现在调用this.email
中的l域如果我在
//现在调用this.email
中调用另一个外部域,将打开一个安全漏洞