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文档。

相关内容

热门资讯

透视详细!aapoker透视脚... 透视详细!aapoker透视脚本下载,aapoker透视脚本下载-都是有辅助方法(哔哩哔哩)1、上手...
透视关于!wepoker透视有... 透视关于!wepoker透视有没有,wepoker透视脚本下载-好像真的是有辅助方法(哔哩哔哩)1、...
透视有挂!wepoker手机插... 透视有挂!wepoker手机插件,wejoker开挂-竟然是有辅助app(哔哩哔哩)1、首先打开辅助...
透视解迷!aapoker ai... 透视解迷!aapoker ai插件,aapoker辅助怎么用-本来是真的有辅助神器(哔哩哔哩)1、游...
透视必备!aapoker安装包... 透视必备!aapoker安装包怎么使用,aapoker脚本怎么用-确实真的有辅助方法(哔哩哔哩)1、...
透视开挂!wpk软件是真的吗,... 透视开挂!wpk软件是真的吗,wpk俱乐部是做什么的-一直有辅助app(哔哩哔哩)1、下载好正确养号...
透视揭幕!wpk透视工作室,w... 透视揭幕!wpk透视工作室,wpk私人辅助-真是是真的有辅助app(哔哩哔哩)1、许多玩家不知道辅助...
透视分享!wpk是真的还是假的... 透视分享!wpk是真的还是假的,wpk安卓下载辅助-一贯是有辅助教程(哔哩哔哩)1、首先打开辅助器下...
透视总结!wpk有那种辅助吗,... 透视总结!wpk有那种辅助吗,wpk透视怎么安装-真是真的有辅助攻略(哔哩哔哩)1、辅助器安装包、辅...
透视开挂!wepoker私人局... 透视开挂!wepoker私人局辅助器怎么用,wepoker俱乐部辅助器-一直有辅助软件(哔哩哔哩)透...