【问题标题】:I want to passing id (stored in firestore) from page to another page in ionic4 App我想在ionic 4 App中将id(存储在firestore中)从页面传递到另一个页面
【发布时间】: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


    【解决方案1】:

    如果 details.page 是在模式中查看,那么我认为你可以将数据传递给 ModalController 以查看新的

    最好的解决方案是使用 ModalController 将单个新闻数据传递到 details.page。

    【讨论】:

      猜你喜欢
      • 2014-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-26
      相关资源
      最近更新 更多