Angular 有角度的火箭弹发射区
我正在尝试构建此功能,以便在我的应用程序的配置文件页面上载配置文件图像,问题是由于图片上载功能,我得到了Angular 有角度的火箭弹发射区,angular,firebase,ionic-framework,angularfire2,Angular,Firebase,Ionic Framework,Angularfire2,我正在尝试构建此功能,以便在我的应用程序的配置文件页面上载配置文件图像,问题是由于图片上载功能,我得到了ZoneAwarePromise。我尝试了很多不同的方法,但无法改变结果 有人能帮我吗?我做错了什么 上传服务.ts pictureUpload(file: any, uid: string) { return this.afUpload.upload('profile/' + uid, file); } onCreateUser() { const picture = th
ZoneAwarePromise
。我尝试了很多不同的方法,但无法改变结果
有人能帮我吗?我做错了什么
上传服务.ts
pictureUpload(file: any, uid: string) {
return this.afUpload.upload('profile/' + uid, file);
}
onCreateUser() {
const picture = this.uploadService.pictureUpload(this.fileInput.nativeElement.files['0'], currentUserID).then(
async (data) => {
try {
return data.ref.getDownloadURL();
} catch {
console.error();
} finally {
const email = this.userProfileForm.value.email;
const firstName = this.userProfileForm.value.firstName;
const lastName = this.userProfileForm.value.lastName;
const userObj = {
'uid': currentUserID,
'email': email,
'firstName': firstName,
'lastName': lastName,
'picture': picture
};
console.log('the object is');
console.log(userObj);
if (this.editMode) {
return this.db.object('profile/' + currentUserID).update(userObj).then(
() => {
return this.presentToaster('Dados atualizados');
},
(e) => {
this.presentToaster(e);
console.error(e);
}
);
} else {
const load = await this.loadCtrl.create({
message: 'Criando Usuario'
});
await load.present();
return this.db.object('profile/' + currentUserID).set(userObj).then(
() => {
load.dismiss();
return this.navCtrl.navigateRoot('news');
},
(error) => {
load.dismiss();
this.presentToaster(error);
console.error(error);
}
);
}
}
},
(error) => {
console.error(error);
}
);
}
profile.component.ts
pictureUpload(file: any, uid: string) {
return this.afUpload.upload('profile/' + uid, file);
}
onCreateUser() {
const picture = this.uploadService.pictureUpload(this.fileInput.nativeElement.files['0'], currentUserID).then(
async (data) => {
try {
return data.ref.getDownloadURL();
} catch {
console.error();
} finally {
const email = this.userProfileForm.value.email;
const firstName = this.userProfileForm.value.firstName;
const lastName = this.userProfileForm.value.lastName;
const userObj = {
'uid': currentUserID,
'email': email,
'firstName': firstName,
'lastName': lastName,
'picture': picture
};
console.log('the object is');
console.log(userObj);
if (this.editMode) {
return this.db.object('profile/' + currentUserID).update(userObj).then(
() => {
return this.presentToaster('Dados atualizados');
},
(e) => {
this.presentToaster(e);
console.error(e);
}
);
} else {
const load = await this.loadCtrl.create({
message: 'Criando Usuario'
});
await load.present();
return this.db.object('profile/' + currentUserID).set(userObj).then(
() => {
load.dismiss();
return this.navCtrl.navigateRoot('news');
},
(error) => {
load.dismiss();
this.presentToaster(error);
console.error(error);
}
);
}
}
},
(error) => {
console.error(error);
}
);
}
我终于明白了
免责声明:这是我的第一个Firebase项目,因此下面的所有描述都基于我的观察。如果我错了什么,请纠正我,我希望能真正理解这一点。谢谢:)
基本上,当我获取try
时,我希望返回数据,在本例中是data.ref.getDownloadURL()
。因为这将是一个承诺,所以我使用.then
方法接收“完整”数据,然后运行响应中的所有其他内容。我觉得数据只存在于那里
onCreateUser(uForm: FormGroup) {
const currentUserID = this.userAuth.getCurrentUserID();
let picture;
this.uploadService.pictureUpload(this.fileInput.nativeElement.files['0'], currentUserID).then(
async (data) => {
try {
data.ref.getDownloadURL().then(
async (downloadURL) => {
picture = downloadURL;
const email = this.userProfileForm.value.email;
const firstName = this.userProfileForm.value.firstName;
const lastName = this.userProfileForm.value.lastName;
const userObj = {
'uid': currentUserID,
'email': email,
'firstName': firstName,
'lastName': lastName,
'picture': picture
};
if (this.editMode) {
return this.db.object('profile/' + currentUserID).update(userObj).then(
() => {
return this.presentToaster('Dados atualizados');
},
(e) => {
this.presentToaster(e);
console.error(e);
}
);
} else {
const load = await this.loadCtrl.create({
message: 'Criando Usuario'
});
await load.present();
return this.db.object('profile/' + currentUserID).set(userObj).then(
() => {
load.dismiss();
return this.navCtrl.navigateRoot('news');
},
(error) => {
load.dismiss();
this.presentToaster(error);
console.error(error);
}
);
}
//
}
);
} catch (error) {
console.error(error);
}
},
(error) => {
console.error(error);
}
);
}