我的电话线有问题
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”。
答案 0 :(得分:1)
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();
}
有关更多信息,请检查this。
答案 1 :(得分:1)
提供替代解决方案
id | Name
1 |abc
2 |xyz
3 |mn
4 |null
4 |xy
5 |yz
6 |null
7 |yy
100 |null
101 |oo
null |yy