【发布时间】:2018-08-07 10:58:41
【问题描述】:
我的代码似乎正在向服务器发送多个请求并缓存先前发送的请求。不太清楚为什么会这样,但这是代码-
async onSubmit() {
let formData =
{
firstName: this.firstName,
lastName: this.lastName,
gender: this.gender,
dateOfBirth: this.dateOfBirth
};
let url = 'ip';
this.afAuth.authState.subscribe(data => {
if (data && data.email && data.getIdToken(true).then((idToken) => {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': idToken
})
};
this.http.post(url, formData, httpOptions)
.subscribe(data => {
console.log(data;
}, error => {
console.log(error);// Error getting the data
});
}))
window.alert("You have been registered.");
})
}
有人知道这里发生了什么吗?
【问题讨论】:
-
很难说没有minimal reproducible example。
this.afAuth.authState是否发出多个值?每一个都会触发一个新的请求。还是onSubmit被多次调用?尝试输入一些console.logs 看看它会到达哪里。
标签: angular firebase-authentication httpclient angularfire2