【发布时间】:2018-04-30 15:28:56
【问题描述】:
我上了这门课:
export class Project {
$key: string;
file: File;
name: string;
title: string;
cat: string;
url: string;
progress: number;
createdAt: Date = new Date();
constructor(file: File) {
this.file = file;
}
}
我有上传组件,我将所有这些信息上传到我的数据库/存储中,它工作正常。
然后我在 home.component 中显示所有项目,如下所示:
上传服务:
getUploads() {
this.uploads = this.db.list(`profile/${this.auth.userId}/project`).snapshotChanges().map((actions) => {
return actions.map((a) => {
const data = a.payload.val();
this.showVisualContent(data.url, data.name);
const $key = a.payload.key;
const $ref = a.payload.ref;
return { $key, ...data, $ref };
});
});
return this.uploads;
}
Home.Component:
uploads: Observable<Project[]>;
ngOnInit() {
this.uploads = this.navSrv.getUploads();
}
Home.html:
<div *ngFor="let project of uploads | async" class="responsive-width">
<mat-card-title class="project-card-title">{{project.name}}</mat-card-title>
</div>
通过这种方式,我展示了 home.component 中的所有项目。我想要的是:
- 我单击 home.component 中的一个项目。
- 转到子组件
- 仅查看点击的项目信息(不是所有项目)。
我对事件发射器知之甚少(也许我需要使用它们),但我真的不知道如何获取我单击的项目并将其显示在子组件中。怎么做 ?
getOneProject() { //and pass it to another component
}
【问题讨论】:
标签: javascript angular typescript firebase