Attempting to retrieve an item from Firebase within an Ionic Angular application

I'm in the process of extracting data from an object to use in a detailed view.

The structured data is as follows:

async createRecord() {
    const user = await this.fbauth.authState.pipe(first()).toPromise();
    const record = {};
    record['Name'] = this.roomName;
    record['Number'] = this.roomNumber;
    record['Description'] = this.roomDescription;
    record['User'] = { email: user.email };
    this.crudService.create_NewRoom(record).then(resp => {
      this.roomName = "";
      this.roomNumber = undefined;
      this.roomDescription = "";
      this.roomUser = toString();
      console.log(resp);
      this.router.navigate(['rooms']);
    })
      .catch(error => {
        console.log(error);
      });
  }

service.ts

read_Room(id) {
    return this.firestore.doc('Rooms/' + id);
  }

create_NewRoom(record) {
    return this.firestore.collection('Rooms').add(record);
  }

room.page.ts:

roomView(record) {
    const navigationExtras: NavigationExtras = {
      queryParams:{
        info: this.crudService.read_Room(record)
      }
    }
    this.router.navigate(["roomview"], navigationExtras);
  }
}

roomview.page.ts:

constructor(private route: ActivatedRoute, private router: Router) { 
      this.route.queryParams.subscribe(params => {
          if (params && params.info) {
            this.data = params.info;
          }
          console.log(params);
      });
  }

roomview.page.html

<ion-card-title>
   {{ data }}
</ion-card-title>

However, upon receiving the information, I only see:

{info: "[object Object]"} info: "[object Object]" proto: Object

Is there any way for me to display the actual data within the object, like Name and Number? I would greatly appreciate any assistance!

Answer №1

When using @angular/fire, for your read_Room(id) method, consider implementing something similar to the following in order to extract data from firestore:

read_Room(id) {
  this.firestore.collection('Rooms').doc(id).ref.get().then(r => {
    return r.data();
  });
}

For more guidance, check out https://firebase.google.com/docs/firestore/query-data/get-data.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue encountered when using FormData to upload a file in Angular 6

I've been working on creating a file uploading system using Angular 6 for the front end and Lumen for the back end API. Strangely, while I can successfully upload files using Postman directly to the API, I'm facing issues when trying to do the sa ...

Exploring the utilization of ngModel within a tag that is selector-based

As a newcomer to Angular 2, I have encountered a challenge with forms that contain multiple text boxes, checkboxes, labels, and drop-downs. When including all these controls in my HTML, the page becomes too long. To address this issue, I would like to crea ...

Can the ElasticSearch standard Node client be considered secure for integration with cloud functions?

When working with my Typescript cloud functions on GCP, I have been making direct HTTP requests to an ElasticSearch node. However, as my project expands, I am considering switching to the official '@elastic/elasticsearch' package for added conven ...

The quantity of documents queried does not align with the number of data counts retrieved from Firestore

Facing an issue with calculating the Firestore read count as it keeps increasing rapidly even with only around 15 user documents. The count surges by 100 with each page reload and sometimes increases on its own without any action from me. Could this be due ...

Navigating Routes with Router in Angular 7: A Step-by-Step Guide

Within my sidebar navigation component, the sidebar.component.html file is structured as follows: <nav class="navbar navbar-expand-lg navbar-dark bg-primary fixed-top" id="sideNav"> <a class="navbar-brand" href="#page-top"> <span cl ...

Guide for launching Electron on a local host server during development and for production builds

I have a project using Next.js + Electron + Typescript. I used the npx create-next-app --example with-electron-typescript command to generate the initial code. When I run npm run dev (which actually runs npm run build-electron && electron . ), the ...

Should I develop a visual touch-based application using Ionic or Meteor?

Imagine an app where there is a hand image displaying five fingers. An interesting feature allows users to tap on any of the fingers, triggering a pop-up window that sends data to the server. Can this unique interaction, involving tapping on a picture (no ...

Transform the object into a date once it initiates at 1

After integrating the angular bootstrap datepicker component into my application, I encountered an issue with converting the selected date object {year: 1993, month: 8, day: 9} into a Date object. The conversion is successful, but the resulting date is shi ...

Modifying the value upon saving in Adonis JS model

Using Adonis js I am facing an issue when trying to convert an ISO string to Datetime while saving data (the opposite of serializing DateTime fields to ISO string). I cannot find a way to do this in the model, like I would with a mutator in Laravel. Whene ...

Ways to display dynamic information in a vertical list using HTML (MEAN stack)

I am receiving an array of data from the backend and looking for a way to display them in a vertical list using HTML. Can anyone help me with this? Below is my current code snippet. TS: this.sub = this.route.params.subscribe(params => { this.http.g ...

Tips for displaying dynamic data using innerHTML

Recently, I set out to implement an infinite scroll feature in Angular 2 using JavaScript code (even though it may seem a bit unusual to use JavaScript for this purpose, it's actually working perfectly). Initially, I was able to create an infinitely s ...

Exploring the functionality of the Angular dist folder after building with multiple projects

In my current Angular project, I've divided the application into three separate applications for improved build time optimization - App1, App2, and App3. When testing locally, I individually build each project and then manually copy the main.js files ...

Unit testing in Jasmine for Angular components involving the subscribe method

------Service file ------- postStatus(status: String) { return this.http .post(url, null, { headers: new HttpHeaders({"Content-Type": "application/json"}), observe: "response" }) .subscribe( res ...

akka-http integrated with angular2 routing

Currently, I am facing an issue with serving my Angular2(rc3) app from akka-http (a Scala rest framework). The problem lies in routing. Whenever a request is made, spray attempts to locate /my/endpoint/declared/in/angular as a regular resource. How can I r ...

Revolutionize your Angular applications with dynamic template loading techniques

I recently developed a new component called componentB, which shares a similar template with another component, componentA. Currently, when a specific url is accessed, the original componentA is loaded. However, I want to load a slightly modified template ...

How can I retrieve elements from an array that match a certain criteria and update the corresponding objects in

When an array contains matching IDs, the goal is to merge these objects into one object without affecting the original array. The current code only returns matching objects, but the expected result should combine them as described. main.ts const arr = [{ ...

Guide on generating a video thumbnail using JavaScript Application

Searching for a way to easily create a thumbnail from a video for uploading alongside the video itself to a server? I've been looking for JavaScript libraries to simplify the process without much luck. The scenario involves the user selecting a video ...

What is the process for extracting Form-Data details with a SAML Response in the header section of the network tab from a browser within an Angular 8 application

I am currently working on implementing IDP authentication for my Angular 8 application. The process involves my application redirecting to the IDP server, which then provides a SAML response for further authorization. This SAML response can be found in t ...

A guide on resolving the issue with node module live-server by switching from using require('opn') to require('open')

While attempting to deploy to my AWS environment, I encountered an error in the nodejs.log. /var/app/current/node_modules/opn/index.js:11 const wslToWindowsPath = async path => { ^^^^ SyntaxError: Unexpected identifier ...

Incorporating Angular with a python PDF generator library

How can an external Python PDF generator library be integrated with Angular? Please provide a detailed explanation with example. ...