SIMPLEST
На самом деле, поскольку подписка является синхронной.Даже это будет работать
// after uploading the image returns path
private async imageUpload(): Promise <string> {
try {
let img = await this.file.upload(this.imageToUpload, 'fileInput_image')
img.subscribe((path: string) => {
this.bg_img_url.setValue(path)
console.log(this.bg_img_url.value) // returns url
})
return this.bg_img_url.value
}
}
// after uploading the icon returns path
private async iconUpload(): Promise <string> {
try {
let icon = await this.file.upload(this.iconToUpload, 'fileInput_icon')
icon.subscribe((path: string) => {
this.item_icon.setValue(path)
console.log(this.item_icon.value) // returns url
})
return this.item_icon.value
}
}
ДРУГИЕ ВАРИАНТЫ
Вы должны либо вернуть Promise из обеих функций, как это
// after uploading the image returns path
private async imageUpload(): Promise <string> {
return new Promise(resolve => {
try {
let img = await this.file.upload(this.imageToUpload, 'fileInput_image')
img.subscribe((path: string) => {
this.bg_img_url.setValue(path)
console.log(this.bg_img_url.value) // returns url
resolve(this.bg_img_url.value)
})
}
})
}
// after uploading the icon returns path
private async iconUpload(): Promise <string> {
return new Promise(resolve => {
try {
let icon = await this.file.upload(this.iconToUpload, 'fileInput_icon')
icon.subscribe((path: string) => {
this.item_icon.setValue(path)
console.log(this.item_icon.value) // returns url
resolve(this.item_icon.value)
})
}
})
}
ИЛИ rxjs, как это
// after uploading the image returns path
private async imageUpload(): Promise <string> {
try {
let img = await this.file.upload(this.imageToUpload, 'fileInput_image')
img.pipe(
switchMap((path: string) => {
this.bg_img_url.setValue(path)
console.log(this.bg_img_url.value) // returns url
return this.bg_img_url.value
})
).toPromise()
}
}
// after uploading the icon returns path
private async iconUpload(): Promise <string> {
try {
let icon = await this.file.upload(this.iconToUpload, 'fileInput_icon')
icon.pipe(
switchMap((path: string) => {
this.item_icon.setValue(path)
console.log(this.item_icon.value) // returns url
return this.item_icon.value
})
).toPromise()
}
}