Как я могу вызвать переменную в конструкторе?
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;
после {this.email = user.email;
Возможно, вы можете попробовать методы жизненного цикла в Nav Controller, которые могут запускаться на разных этапах событий страницы.
Вы также можете выполнить вызов в подписчике. Или вызовите функцию изнутри, чем вы знаете, что ваши переменные установлены.
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;
}
→ не проверено
// NOW CALLIG this.email
this.url
асинхронны .. Ваше назначениеthis.url
происходит доthis.url
функции подписки