我有upload.module提供的upload.service。当我在upload.component中使用它时,它工作正常:
export class UploadsListComponent implements OnInit {
uploads: Observable<Upload[]>;
showSpinner = true;
constructor(private upSvc: UploadService) { }
ngOnInit() {
this.uploads = this.upSvc.getUploads();
console.log("upload list upload :")
this.uploads.subscribe(() => this.showSpinner = false);
}
}
Upload.component.html:
<div *ngFor="let upload of uploads | async">
<upload-detail [upload]='upload'></upload-detail>
<img src="{{upload.url}}" alt="">
</div>
当我在另一个模块组件中使用它时,upload.url为null。
我觉得这个功能不好:
uploads: Observable<Upload[]>;
getUploads() {
this.uploads = this.db.list(`${this.auth.userId}`).snapshotChanges().map((actions) => {
return actions.map((a) => {
const data = a.payload.val();
const $key = a.payload.key;
return { $key, ...data };
});
});
return this.uploads;
}
为什么upload.url只显示一次?
注意:不要看控制台它有一些无关紧要的错误和一些不好的console.log