Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 上载图像,无法读取属性';订阅';未定义的_Javascript_Angular - Fatal编程技术网

Javascript 上载图像,无法读取属性';订阅';未定义的

Javascript 上载图像,无法读取属性';订阅';未定义的,javascript,angular,Javascript,Angular,我有一个简单的创建帖子功能,我想在填写标题、内容和图像时创建帖子: 但是,当我上传进度条填充的图像时,图像会上载到firebase,但它不允许我创建帖子,当我在控制台中测试它时,它会出现以下错误: 代码如下: 从'@angular/core'导入{Component,OnInit}; 从“../../core/auth.service”导入{AuthService}; 从“angularfire2/storage”导入{AngularFireStorage}; 从“../post.serv

我有一个简单的创建帖子功能,我想在填写标题、内容和图像时创建帖子:

但是,当我上传进度条填充的图像时,图像会上载到firebase,但它不允许我创建帖子,当我在控制台中测试它时,它会出现以下错误:

代码如下:

从'@angular/core'导入{Component,OnInit};
从“../../core/auth.service”导入{AuthService};
从“angularfire2/storage”导入{AngularFireStorage};
从“../post.service”导入{PostService};
从“rxjs/Observable”导入{Observable};
@组成部分({
选择器:“应用程序发布面板”,
templateUrl:'./post dashboard.component.html',
样式URL:['./post dashboard.component.css']
})
导出类PostDashboardComponent实现OnInit{
标题:字符串;
image:string=null;
内容:字符串;
buttonText:string=“创建帖子”
上载百分比:可见
下载URL:可观察
建造师(
私有身份验证:身份验证服务,
私人邮政服务:邮政服务,
专用存储:AngularFireStorage
) { }
恩戈尼尼特(){
}
上载映像(事件){
const file=event.target.files[0]
const path=`posts/${file.name}`
if(file.type.split('/')[0]!=='image'){
返回警报(“仅图像文件”)
}否则{
const task=this.storage.upload(路径、文件)
this.uploadPercent=task.percentageChanges()
console.log('Image Uploaded!')
this.downloadURL.subscribe(url=>this.image=url)
}
}
createPost(){
常数数据={
作者:this.auth.authState.displayName | | this.auth.authState.email,
authorId:this.auth.currentUserId,
content:this.content,
图像:这个图像,
发布日期:新日期(),
标题:this.title
};
this.postService.create(数据)
this.title=“”
this.content=“”
this.image=''
this.buttonText='Post Created!'
setTimeout(()=>(this.buttonText=“Create Post”),3000;
}

}
正如错误所说,
this.downloadURL
未定义,请确保在使用它之前已初始化