gpt4 book ai didi

javascript - 从 Firebase 存储获取的 URL 未显示在 Ionic 3 中的

转载 作者:行者123 更新时间:2023-12-02 22:17:10 25 4
gpt4 key购买 nike

我正在尝试在我的 ionic 3 项目上显示从 firebase 存储获取的 URL。我在尝试获取标签中 [src] 的 URL 时遇到问题。我试图以字符串的形式传递 URL,但什么也没有出现。当我尝试 console.log 字符串时,控制台中也没有显示任何内容。

这是我的代码:

.html:

 <ion-img class="imgBooking" [src]=retrievedRestaurantImage  item-content></ion-img>

.ts:

retrievedRestaurantImage:any;

...

var storage = firebase.storage();
var pathReference = storage.ref('Restaurant/ABC_Restaurant/ABCRestaurantPicture.jpg');

pathReference.getDownloadURL().then(function(url){

console.log(url); <-- This URL appears in the console, and after clicking on the link, it directs me to the correct picture.
this.retrievedRestaurantImage = url;
console.log(this.retrievedRestaurantImage); <-- Does not display in console, image is not updated in the <ion-img> tag.

}).catch(function(error) {
// Handle any errors
});

这是我的控制台的图片: enter image description here

当我点击控制台中的 URL 时,它会将我定向到正确的图像(来自 Firebase 存储)。

我似乎无法将图像取出来。请帮忙!

最佳答案

更改此:


pathReference.getDownloadURL().then(function(url){

console.log(url); <-- This URL appears in the console, and after clicking on the link, it directs me to the correct picture.
this.retrievedRestaurantImage = url;
console.log(this.retrievedRestaurantImage);

进入此:


pathReference.getDownloadURL().then((url) =>{

console.log(url); <-- This URL appears in the console, and after clicking on the link, it directs me to the correct picture.
this.retrievedRestaurantImage = url;
console.log(this.retrievedRestaurantImage);

使用箭头功能:

An arrow function does not have its own this. The this value of the enclosing lexical scope is used; arrow functions follow the normal variable lookup rules. So while searching for this which is not present in current scope, an arrow function ends up finding the this from its enclosing scope.

关于javascript - 从 Firebase 存储获取的 URL 未显示在 Ionic 3 中的 <ion-img [src]=...> 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59350385/

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