this.service.service1().subscribe( res1 => {
this.service.service1().subscribe( res2 => {
this.service.service1().subscribe( res3 => {
this.funcA(res1, res2, res3);
});
});
});
Run Code Online (Sandbox Code Playgroud)
我需要将三个数据从三个不同的API传递给一个函数.
在订阅中订阅是一种好习惯吗?
如果没有,请建议最佳方式.
我一直在浏览angularfire2文档,以从存储中检索downloadURl。我希望这里缺少一些简单的东西。
该文档指出:
@Component({
selector: 'app-root',
template: `<img [src]="profileUrl | async" />`
})
export class AppComponent {
profileUrl: Observable<string | null>;
constructor(private storage: AngularFireStorage) {
const ref = this.storage.ref('users/davideast.jpg');
this.profileUrl = ref.getDownloadURL();
}
}
Run Code Online (Sandbox Code Playgroud)
但是,一旦我上传了图片,我想以字符串形式返回下载网址以上传到firestore。我需要一个外部服务的下载网址。
我的功能
uploadImage(base64data) {
const filePath = (`myURL/photo.jpg`);
const storageRef = firebase.storage().ref();
var metadata = {
contentType: 'image',
cacheControl: "public, max-age=31536000",
};
const ref = this.storage.ref(filePath);
const task = ref.putString(base64data, 'data_url', metadata).then(() => {
var downloadURL = ref.getDownloadURL();
})
}
Run Code Online (Sandbox Code Playgroud)
这样可以完美上传图像。不过,我会再喜欢写的下载网址,公司的FireStore。当控制台记录我的“ downloadURL”变量时,我得到以下信息:
PromiseObservable {_isScalar:假的,承诺:Y,调度:未定义}
下载是承诺观察到里面。如何仅将下载URL字符串作为变量?一旦有了,我就可以整理出Firestore更新了。