Utilizing a Firebase function with Angular

I created the following function:

  retrieveLikedProperties(): AngularFirestoreCollection<any> {
    return this.afs.collection('users', ref =>
      ref.where('uid', '==', this._auth.currentUserId)
        .where('likedProp', '==', true)
    );
  }

When attempting to call it, I used the following method:

  ngOnInit() {
      this._property.retrieveLikedProperties().subscribe(likedProp => {
        console.log(likedProp);
        this.likedProp = likedProp;
      });

    }

Unfortunately, I encountered an error stating:

ERROR TypeError: this._property.retrieveLikedProperties is not a function

Does anyone have insights on why this is happening, and how to correctly call this function?

Answer №1

Your service function getAllLikedProperties() needs to be updated as it currently does not return an observable, but rather the value of your filtered afs collection.

To fix this, modify your function to return an observable that you can subscribe to:

getAllUserLikedProperties(): AngularFirestoreCollection<any> {

    const properties$: Subject<any> = new Subject<any>();
    properties$.next(this.afs.collection('users', ref =>
      ref.where('uid', '==', this._auth.currentUserId)
        .where('likedProp', '==', true)
    ));
   return properties$;
}

Another approach is to utilize RxJs's of operator to handle the observable stream:

import { of } from 'rxjs';

getAllUserLikedProperties(): AngularFirestoreCollection<any> {
    return of(this.afs.collection('users', ref =>
      ref.where('uid', '==', this._auth.currentUserId)
        .where('likedProp', '==', true)
    ));
}

If you prefer not to subscribe explicitly, you can directly assign the value like this:

ngOnInit() {
    this.likedProp = this._property.getAllUserLikedProperties();
}

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

Scroll the div that is dynamically filled without affecting the scrolling of the main page

My current struggle involves using iScroll in my web project. The goal is to populate a list with articles and slide in a div over the list to display the selected article. While the basic functionality is in place, I face an issue where scrolling through ...

Troubleshooting problem with transmitting data using the b4j jQuery WebSocket library

I'm seeking guidance on the process of sending data through a custom library that connects to a Java server operating as a WebSocket server. The code I'm using for successful connection is: <script src="https://ajax.googleapis.com/ajax/libs/ ...

Displaying or concealing list elements in Angular 6

I am working on a simple Angular app that displays a list of items. I want the behavior to be such that when the first item in the list is clicked, its description (card) should be displayed. And, if the second item is clicked and its description is displa ...

The IISNode website displays directory contents instead of launching the server.js file

Having trouble configuring IISNode to automatically serve the main server.js application file for my node application. Currently, when I navigate to http://localhost:80/ where my app is hosted, it just displays the folder contents instead of running the se ...

Altering the appearance of an input field upon submission

https://jsfiddle.net/3vz45os8/7/ I'm working on a JSFiddle where I am trying to change the background color of input text based on whether the word is typed correctly or incorrectly. Currently, it's not functioning as expected and there are no e ...

Executing a function after a subscriber has finished in Angular 8+

Welcome fellow learners! Currently, I am diving into the world of Angular and Firebase. I am facing an interesting challenge where I fetch ticket data from my collection and need to add new properties to it. However, the issue arises when my ordering funct ...

Warning: data and salt parameters are necessary, please provide them

Issue: I am encountering an error with registering a new user, specifically when using Postman. I'm not sure why this error is occurring only in Postman. Additionally, I am facing proxy problems where requests cannot be proxied from localhost:3000 to ...

What is the definition of XLLS?

Is there a connection between the "XLLS" expression and AJAX / Javascript? What is the actual meaning of XLLS? Thank you in advance. including text from a comment in response ...when I searched for an answer on Google, all I found was Excel XLLs but no ...

Learn how to alter the website's overall appearance by changing the background or text color with a simple click on a color using Angular

Is there a way to dynamically change the background color or text color of the entire website when a user clicks on a color from one component to another? I know I need to use the Output decorator, but how can I implement this? style.component.html <di ...

Reading Properties in VueJS with Firebase

<template> <div id="app"> <h1 id="title"gt;{{ quiz.title }}</h1> <div id="ques" v-for="(question, index) in quiz.questions" :key="question.text"> <div v-show="index = ...

The issue at hand is why the closure is not functioning properly when variables are assigned to the callback of the getCurrentLocation function

Apologies for the extensive amount of code, but it seems like there may be an issue with AppMobi's getCurrentLocation function in this scenario. The problem arises when tapping on list elements triggers an asynchronous getCurrentLocation call which up ...

Different Ways to Access an Array in an EJS Template

After receiving a list of IDs from an API, I need to include them in a URL within an EJS template to retrieve the correct items. For example, the URL format is: Here are some example IDs: 526 876 929 The desired output inside the EJS template: <li&g ...

utilize the entire space designated for the <router-outlet> component

I am working with 3 components: <menu (setAnimal)='setAnimal($event)' ></menu> //PrincipalComponent <router-outlet (activate)='onActivate($event)'></router-outlet> <footer></footer> The red border ...

release a Node.js module on NPM

Being a complete beginner in creating npm packages using typescript2 and angular2, I find myself in need of creating an npm package and publishing it on our company's private repository. I've managed to generate files like d.ts and .js. But how ...

The behavior of Elementor lightbox buttons upon being clicked

When using Android, I've noticed that the lightbox briefly displays a semitransparent cyan bar on the left and right buttons when they are pressed. Is there a way to control or prevent this behavior? Any suggestions would be appreciated! Thanks in adv ...

What steps can I take to troubleshoot a non-functional button in a Bootstrap 5 Modal?

I have a Django based web site that utilizes Bootstrap 5 for styling. Among the data presented on the site is a table with a notes column containing lengthy text. To enhance readability and keep the table compact, I attempted to integrate the Bootstrap Mod ...

What is the purpose of declaring data types such as string, number, boolean, void, and others in Angular 2

I'm curious as to why programmers declare classes in individual scope or something. For example, take a look at this code snippet: result: boolean = false public generateRand(x): void { } This is also similar to the following: result = false publi ...

items within the grid container are positioned without being constrained to rows and columns

After using the Container element, I noticed that all my grid items are displaying in columns instead of rows. How can I correct this layout issue? https://i.stack.imgur.com/9BjOA.png Click here to access the project link. ...

Direct users to a different page upon reloading the page in Django

Currently working on a web application with the Django framework. In one of the forms in my app, I am looking to automatically redirect to a new page upon reloading the current page, rather than when the form is submitted. Any insights from the community w ...

Utilizing Angular: Integrating the Http response output into a map

I have a situation where I am making multiple HTTP calls simultaneously from my Angular application. The goal is to store the responses of these calls in a Map. data: Map<number, any> = new map<number,any>(); --------------------------------- ...