【发布时间】:2019-07-11 05:52:17
【问题描述】:
我想将我存储在 Firestore 数据库中的 ID 从页面传递到 Ionic4 应用程序中的另一个页面
我有一个新闻应用程序,我从 Firestore 中检索了内容,我希望当我点击新闻时,它必须在详细信息页面中显示详细信息 我的代码简介:
news.page.html
<ion-content padding>
<ion-item *ngFor=" let count of data">
<h5>{{count.title}}<ion-button (click)="goToDetail()">click for details</ion-button>
<img src="{{count.image}}">
</h5>
</ion-item>
news.page.ts
export class FilmsPage implements OnInit {
data: any;
constructor(public db: AngularFirestore, private router: Router) { }
ngOnInit() {
this.getAllPosts().subscribe((data) => {
this.data = data;
console.log(data);
});
}
getAllPosts(): Observable<any> {
return this.db.collection<any>('123').valueChanges ();
}
goToDetail() {
this.router.navigateByUrl('/details/{{count.id}}');
}
}
details.page.ts
export class DetailsPage implements OnInit {
id: string;
constructor(private router: ActivatedRoute, private afs: AngularFirestore) {
}
ngOnInit() {
this.id = this.router.snapshot.paramMap.get('id');
console.log(this.id);
}
}
details.page.html
<ion-content padding>
{{id}}
</ion-content>
但是当我运行这段代码时,它只是在 details.page.html 中显示了 {{count.id}} .. 为什么???请问有人能解决这个问题吗
【问题讨论】:
标签: ionic-framework ionic3 angular6 angular7 ionic4