firebase fetch 下载 url 无限循环请求
firebase fetch download url infinite loop request
当尝试从 firebase 存储中获取 DownloadURL 时,我遇到了同样的问题,一个无限请求
这是我的代码:
我的组件HTML
<div *ngIf="(geturlimagefromserver() | async) as imgc ;else loadiing ">
<img
class="card-img-top"
alt="robot3_image_robot.png"
[src]="imgc | ''"
data-holder-rendered="true"
style=" margin: 4px;
width: 246px;
height: 175px; display: block;"
/>
</div>
<ng-template #loadiing>
<div class="text-menuted">Loading image...</div>
</ng-template>
Mycomponent组件
geturlimagefromserver():Observable <any>{
console.log('i get hier infinite loop ');
return this.RobotService.getMetadata(path);
}
i saw in my console infinity print the word "i get hier infinite loop "
MyService服务
getMetadata() :Observable <any>{
const ref = this.storage.ref('myfile/img1');
return ref.getDownloadURL();}
大问题
是当我调用函数时:
geturlimagefromserver()
在 Mycomponent.html
我的浏览器在网络中收到无限请求
但是当我调用我的函数时:
Mycomponent.component.ts 中的 getMetadata()
像这样
this.MyService.getMetadata().subscribe(data=>{
})
console.log("its work so fun");
console.log(data);
}
its work so fun and he give met exactly url downloader from fire storage
与其说你处于 无限 循环中,还不如说函数 get Url 每次 angular 检查 DOM,所以它看起来像一个无限循环。
出于上述原因,您应该避免直接在 html 上使用函数,在组件上执行,或者您可以使用管道。
简而言之,这不是 firebaseStorage 的问题,而是 changeDetection 在 Angular 中的工作方式。
当尝试从 firebase 存储中获取 DownloadURL 时,我遇到了同样的问题,一个无限请求 这是我的代码:
我的组件HTML
<div *ngIf="(geturlimagefromserver() | async) as imgc ;else loadiing ">
<img
class="card-img-top"
alt="robot3_image_robot.png"
[src]="imgc | ''"
data-holder-rendered="true"
style=" margin: 4px;
width: 246px;
height: 175px; display: block;"
/>
</div>
<ng-template #loadiing>
<div class="text-menuted">Loading image...</div>
</ng-template>
Mycomponent组件
geturlimagefromserver():Observable <any>{
console.log('i get hier infinite loop ');
return this.RobotService.getMetadata(path);
}
i saw in my console infinity print the word "i get hier infinite loop "
MyService服务
getMetadata() :Observable <any>{
const ref = this.storage.ref('myfile/img1');
return ref.getDownloadURL();}
大问题
是当我调用函数时:
geturlimagefromserver() 在 Mycomponent.html 我的浏览器在网络中收到无限请求
但是当我调用我的函数时: Mycomponent.component.ts 中的 getMetadata() 像这样
this.MyService.getMetadata().subscribe(data=>{
})
console.log("its work so fun");
console.log(data);
}
its work so fun and he give met exactly url downloader from fire storage
与其说你处于 无限 循环中,还不如说函数 get Url 每次 angular 检查 DOM,所以它看起来像一个无限循环。
出于上述原因,您应该避免直接在 html 上使用函数,在组件上执行,或者您可以使用管道。
简而言之,这不是 firebaseStorage 的问题,而是 changeDetection 在 Angular 中的工作方式。