Angular路由参数在传递Firestore文档的Id时会自动转换为小写。
创始人
2024-10-28 01:00:38
0

要解决这个问题,可以在路由参数传递之前手动将文档的Id转换为小写。以下是一个示例解决方法:

  1. 首先,导入Angular的路由模块和Firestore模块:
import { RouterModule, Routes, ActivatedRoute } from '@angular/router';
import { AngularFirestore } from '@angular/fire/firestore';
  1. 在路由模块中定义一个路由参数,例如:
const routes: Routes = [
  { path: 'document/:id', component: DocumentComponent }
];
  1. 在相应的组件中,注入ActivatedRoute和AngularFirestore,并在构造函数中使用ActivatedRoute来获取路由参数:
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { AngularFirestore } from '@angular/fire/firestore';

@Component({
  selector: 'app-document',
  templateUrl: './document.component.html',
  styleUrls: ['./document.component.css']
})
export class DocumentComponent implements OnInit {
  documentId: string;

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

  ngOnInit() {
    this.route.paramMap.subscribe(params => {
      this.documentId = params.get('id').toLowerCase(); // 将路由参数转换为小写
      this.getDocument(this.documentId);
    });
  }

  getDocument(id: string) {
    // 使用转换后的文档Id来获取Firestore文档
    this.firestore.collection('documents').doc(id).valueChanges().subscribe(document => {
      console.log(document);
    });
  }
}

现在,当路由参数传递给DocumentComponent组件时,它会自动将文档的Id转换为小写,并使用转换后的Id获取Firestore文档。

相关内容

热门资讯

透视诀窍!wepoker有插件... 透视诀窍!wepoker有插件吗(HHpoker模拟器)原来存在有辅助教程(哔哩哔哩)1、每一步都需...
透视讲义!aapoker脚本(... 透视讲义!aapoker脚本(AApoker免费)一贯存在有辅助神器(哔哩哔哩)1、操作简单,无需a...
透视经验!hhpoker怎么开... 透视经验!hhpoker怎么开透视(WePoKer咨询)竟然是真的有辅助教程(哔哩哔哩)1、进入游戏...
透视机巧!wepoker私人定... 透视机巧!wepoker私人定制透视(HHpoker内部)其实是有辅助方法(哔哩哔哩)1、进入游戏-...
透视总结!epoker底牌透视... 透视总结!epoker底牌透视(WPK四人)竟然有辅助技巧(哔哩哔哩)1.epoker底牌透视 选牌...
透视操作!德普辅助器怎么用(W... 透视操作!德普辅助器怎么用(WePoKer辅助器)一贯真的有辅助app(哔哩哔哩)透视操作!德普辅助...
透视诀窍!we poker辅助... 透视诀窍!we poker辅助器下载(WePoKer正版)一贯真的是有辅助教程(哔哩哔哩)在进入we...
透视步骤!wepoker有没有... 透视步骤!wepoker有没有挂(WePoKer私人局)一直是有辅助攻略(哔哩哔哩)1、每一步都需要...
透视讲义!wepoker透视脚... 透视讲义!wepoker透视脚本是什么(WPK辅助)确实真的是有辅助神器(哔哩哔哩)1、wepoke...
透视经验!poker worl... 透视经验!poker world辅助器(WePoKer h5)真是存在有辅助app(哔哩哔哩)pok...