【发布时间】:2020-08-31 10:22:49
【问题描述】:
我的线路有问题
this.downloadURL = task.downloadURL()
即使我导入了 AngularFireUploadTask。
import { Component, OnInit } from '@angular/core';
import { AuthService } from '../../core/auth.service';
import { AngularFireStorage, AngularFireStorageReference, AngularFireUploadTask } from 'angularfire2/storage';
import { PostService } from '../post.service';
import { Observable } from 'rxjs/Observable';
@Component({
selector: 'app-post-dashboard',
templateUrl: './post-dashboard.component.html',
styleUrls: ['./post-dashboard.component.css']
})
export class PostDashboardComponent implements OnInit {
title: string;
image: string = null;
content: string;
buttonText: string = "Create Post"
uploadPercent: Observable<number>
downloadURL: Observable<string>
constructor(
private auth: AuthService,
private postService: PostService,
private storage: AngularFireStorage
) { }
ngOnInit() {
}
uploadImage(event) {
const file = event.target.files[0]
const path = `posts/${file.name}`
if (file.type.split('/')[0] !== 'image') {
return alert('only image files')
} else {
const task = this.storage.upload(path, file)
this.downloadURL = task.downloadURL()
this.uploadPercent = task.percentageChanges()
console.log('Image Uploaded!')
this.downloadURL.subscribe(url => this.image = url)
}
}
消息是:“类型上不存在属性‘downloadURL’ 'AngularFireUploadTask'。”。
我应该怎么做才能没有这个问题。
【问题讨论】: