angular - 'AngularFireUploadTask' 类型上不存在'downloadURL'
问题描述
我的线路有问题
this.downloadURL = this.task.downloadURL();
即使我导入了 AngularFireUploadTask。
import { Component, OnInit } from '@angular/core';
import { AngularFireDatabase, AngularFireList } from 'angularfire2/database';
import { Router } from '@angular/router'
import { AngularFireStorage, AngularFireStorageReference, AngularFireUploadTask } from 'angularfire2/storage'
import { Observable, of } from 'rxjs';
@Component({
selector: 'app-userprofile',
templateUrl: './userprofile.component.html',
styleUrls: ['./userprofile.component.css']
})
export class UserprofileComponent implements OnInit {
email: string;
uid: string;
id: any;
myid: string;
userKey: any;
data = {
name : '',
phone : '',
age : '',
address : '',
city : '',
job: '',
email: ''
};
itemList: AngularFireList<any>
itemArray = []
ref: AngularFireStorageReference;
task: AngularFireUploadTask;
downloadURL :Observable<any>;
constructor(private afStorage: AngularFireStorage, public db:AngularFireDatabase, public rout: Router) {
this.email = localStorage.getItem('email')
this.myid = localStorage.getItem('uid')
this.itemList = db.list('users')
this.itemList.snapshotChanges()
.subscribe(actions=>{
actions.forEach(action=>{
let y = action.payload.toJSON()
y['$key'] = action.key
this.itemArray.push(y as ListItemClass)
if(action.payload.child('uid').val() == this.myid) {
this.userKey = action.key
this.itemArray.push(y as ListItemClass)
this.data.name = this.itemArray[0]['name']
this.data.phone = this.itemArray[0]['phone']
this.data.age = this.itemArray[0]['age']
this.data.address = this.itemArray[0]['address']
this.data.city = this.itemArray[0]['city']
this.data.job = this.itemArray[0]['job']
this.data.email = this.itemArray[0]['email']
console.log(this.userKey);
console.log(this.itemArray)
}
})
})
}
ngOnInit() {
console.log(this.email)
console.log(this.myid)
}
upload(event){
const id = Math.random().toString(36).substring(2);
this.ref = this.afStorage.ref(id);
this.task = this.ref.put(event.target.files[0]);
this.downloadURL = this.task.downloadURL();
}
onEdit(){
this.itemList.set(this.myid , {
name : this.data.name,
phone : this.data.phone,
age : this.data.age,
address : this.data.address,
city : this.data.city,
job : this.data.job,
email: this.email,
uid: this.myid
})
this.rout.navigate(['/home']);
}
}
export class ListItemClass {
name : string;
phone : string;
age : string;
address: string;
city: string;
job: string;
email: string;
}
错误是:“AngularFireUploadTask”类型上不存在属性“downloadURL”。
解决方案
image: string = null
....
....
upload(event){
const id = Math.random().toString(36).substring(2);
this.ref = this.afStorage.ref(id);
this.task = this.ref.put(event.target.files[0]);
task.snapshotChanges().pipe(
finalize(() => {
this.downloadURL = ref.getDownloadURL()
this.downloadURL.subscribe(url => (this.image = url));
})
)
.subscribe();
}
有关更多信息,请查看此。
推荐阅读
- mysql - 带有多个and子句的Mysql查询的执行顺序是什么?
- java - 如何限制 ListView 项上显示的字符数
- excel - 我开发的 vba 代码有问题
- wso2 - 使用自定义索赔处理程序的 WSO2 索赔扩展
- php - PHP Excel 禁用单元格..设置受保护
- ios - iOS IAP 用于有限购买数量的商品。消耗还是不消耗?
- eclipse - TestNG 与 eclipse 2019-09 不兼容
- c# - 如何使用 ICsharpCode.TextEditor 组件自动完成标签?
- typescript - 如何将 react javascript 转换为类型脚本?
- c++ - 请解释这个语句(cout << 1 + int((a < b) ^ ((b - a) & 1)) << endl)