gpt4 book ai didi

javascript - angularjs firebase storage getDownloadURL 返回未定义,但它存在

转载 作者:行者123 更新时间:2023-11-28 05:26:54 29 4
gpt4 key购买 nike

为什么内部控制台日志的输出与外部控制台日志的输出不同?
而它们应该是相同的。
我正在寻找的是获取存储在firebase存储中的文件的url。

        var url = spaceRef.getDownloadURL()
.then(function(url){
//$scope.avatar = url;
console.log("inside:", url);
return url;
//console.log(url);
})
.catch(function(error) {
$scope.errMsg = true;
$scope.errorMessage = error.message;
});
console.log("outside:", url);

最佳答案

then是javascript中与Promise相关的函数。仅在评估 getDownloadURL() 后,您才能将输出设置为 url 变量。因此,只有在评估 Promise 后,内部才会打印内容,而外部则记录为未定义或 null 或空...它是异步的。所以区别...

Promis , then()

关于javascript - angularjs firebase storage getDownloadURL 返回未定义,但它存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40072519/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com