AngularFireDocument在访问路由第二次之前不会响应路由更改。
创始人
2024-10-24 21:01:37
0

要解决AngularFireDocument在访问路由第二次之前不会响应路由更改的问题,我们可以使用Angular的ActivatedRoute来监听路由变化,并在每次路由变化时手动更新AngularFireDocument。

以下是一个示例代码,展示了如何使用ActivatedRoute来解决该问题:

在组件中导入所需的库:

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { AngularFireStore, AngularFireDocument } from '@angular/fire/firestore';

@Component({
  selector: 'app-your-component',
  templateUrl: './your-component.component.html',
  styleUrls: ['./your-component.component.css']
})
export class YourComponentComponent implements OnInit {

  document: AngularFireDocument;

  constructor(private route: ActivatedRoute, private firestore: AngularFireStore) { }

  ngOnInit() {
    this.route.params.subscribe(params => {
      const documentId = params['id']; // 从路由参数中获取文档ID

      // 更新AngularFireDocument
      this.document = this.firestore.doc('your-collection/' + documentId);
    });
  }

  // 其他组件逻辑...
}

在上述示例中,我们在ngOnInit函数中使用route.params.subscribe来监听路由参数的变化。当路由参数发生变化时,我们从params对象中提取文档ID,并使用该ID更新AngularFireDocument。这样,每当路由变化时,AngularFireDocument都会被正确更新。

请注意,示例中的'your-collection'应替换为您实际的集合名称,以及'your-component'应替换为您的组件名称。

希望这个示例能解决您的问题!

相关内容

热门资讯

查到实测!xpoker辅助神器... 查到实测!xpoker辅助神器,wepoker私局辅助,果然是真的有挂(有挂攻略)查到实测!xpok...
玩家交流!werplan怎么作... 玩家交流!werplan怎么作弊,cloudpoker怎么开挂,切实是真的有挂(有挂神器)1、许多玩...
今日公布!wepoker轻量版... 今日公布!wepoker轻量版有透视吗,wepoker透视脚本视频,竟然真的有挂(有挂详情)1、该软...
科技分享!wepoker免费透... 科技分享!wepoker免费透视脚本,约局吧德州可以透视吗,切实真的是有挂(有挂头条)1)wepok...
技术分享!wepoker辅助器... 技术分享!wepoker辅助器官方,约局吧德州真的存在透视吗,本来真的有挂(有挂分享)1、wepok...
研究成果!werplan怎么作... 研究成果!werplan怎么作弊,wepokerplus透视脚本免费,总是真的有挂(有挂技术)1、研...
热点推荐!wpk俱乐部怎么作弊... 热点推荐!wpk俱乐部怎么作弊,sohoo辅助,本来是有挂(有挂方法)暗藏猫腻,小编详细说明破解器有...
热点讨论!aapoker安装包... 热点讨论!aapoker安装包怎么使用,hhpkoer辅助挂是真的吗,竟然是真的有挂(有挂头条)1、...
科普!WePoKer辅助器,拱... 科普!WePoKer辅助器,拱趴大菠萝有挂吗,总是真的是有挂(有挂细节)1、下载好正确养号方法之后点...
玩家必备科普!wpk俱乐部辅助... 玩家必备科普!wpk俱乐部辅助器,wepoker亲友圈有用吗,切实有挂(新版有挂)亲,关键说明,透视...