打印字符串angularjs 2-2
我的代码是:打印字符串angularjs 2-2,angular,ionic2,Angular,Ionic2,我的代码是: firebase.auth().onAuthStateChanged(function(user) { if (user) { var user1 = firebase.auth().currentUser; var name, email, photoUrl, password, uid, emailVerified; if (user != null) { name = user1.displayN
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
var user1 = firebase.auth().currentUser;
var name, email, photoUrl, password, uid, emailVerified;
if (user != null) {
name = user1.displayName;
email = user1.email;
photoUrl = user1.photoURL;
emailVerified = user1.emailVerified;
uid = user1.uid; // The user's ID, unique to the Firebase project. Do NOT use
// this value to authenticate with your backend server, if
// you have one. Use User.getToken() instead.
console.log(email);
}
} else {
console.log('no user');
}
});
log(email)以html格式打印电子邮件
<h1>email: {{ email }}</h1>
email:{{email}
什么都别给我打印,为什么?我在谷歌上搜索了一下,但什么都没有。怎么了?要在html中打印,变量应该是类属性。 在组件类中,声明
电子邮件
@Component()
export class cmp{
email:any;
//...
//In your firebase call set in this.email
firebase.auth().onAuthStateChanged((user)=> {//use arrow function to make sure this is correct
if (user) {
let user1 = firebase.auth().currentUser;
let name, photoUrl, password, uid, emailVerified;
if (user != null) {
name = user1.displayName;
this.email = user1.email;//here
photoUrl = user1.photoURL;
emailVerified = user1.emailVerified;
uid = user1.uid; // The user's ID, unique to the Firebase project. Do NOT use
// this value to authenticate with your backend server, if
// you have one. Use User.getToken() instead.
console.log(this.email);
}
} else {
console.log('no user');
}
});
现在,用html显示
{{email}}
要在html中打印,变量应该是类属性。
在组件类中,声明电子邮件
@Component()
export class cmp{
email:any;
//...
//In your firebase call set in this.email
firebase.auth().onAuthStateChanged((user)=> {//use arrow function to make sure this is correct
if (user) {
let user1 = firebase.auth().currentUser;
let name, photoUrl, password, uid, emailVerified;
if (user != null) {
name = user1.displayName;
this.email = user1.email;//here
photoUrl = user1.photoURL;
emailVerified = user1.emailVerified;
uid = user1.uid; // The user's ID, unique to the Firebase project. Do NOT use
// this value to authenticate with your backend server, if
// you have one. Use User.getToken() instead.
console.log(this.email);
}
} else {
console.log('no user');
}
});
现在,用html显示
{{email}}
您应该使用let
而不是var
。请在精彩的[typescript documentation][1][1]中找到解释:@niklas你说得对..谢谢。。但这并不是OP收到问题的真正原因。我宣布它是电子邮件:任何;我这样做了。email=user1.email但什么都没有。控制台日志打印:test1@gmail.com,但是{email}nothing在哪里调用了firebase.auth().onAuthStateChanged
?您可以添加组件和html代码吗?你使用了箭头函数吗?我是新手,但它不是箭头函数,它是从Firebase导入的。你应该使用let
而不是var
。请在精彩的[typescript documentation][1][1]中找到解释:@niklas你说得对..谢谢。。但这并不是OP收到问题的真正原因。我宣布它是电子邮件:任何;我这样做了。email=user1.email但什么都没有。控制台日志打印:test1@gmail.com,但是{email}nothing在哪里调用了firebase.auth().onAuthStateChanged
?您可以添加组件和html代码吗?你使用了箭头功能吗?我是新手,但它不是箭头功能,它是从firebase导入的