Firebase data causing issues with ion-gesture recognition?

Hey there!

I'm currently facing an issue with my ionic app. I added the ion-gesture to my project, but due to the ngFor loop pulling data from Firebase, the cards are unable to move.

Here's a snippet of my code:

<ion-card *ngFor="let postscall2 of postcall2" >
    
      <img class="profilePic"src="https://ucarecdn.com/{{ postscall2.profilePic }}/-/scale_crop/200x200/center/"/>
      <ion-img (click)="open(postscall2)"src="https://ucarecdn.com/{{postscall2.postboost2ID}}/-/preview/{{postscall2.effect}}"></ion-img>
     
        
      
    </ion-card>

And here is the TypeScript part:

import { Component, ElementRef, OnInit, QueryList, AfterViewInit, ViewChildren }from'@angular/core';
    import { AngularFirestore, AngularFirestoreDocument } from "@angular/fire/firestore";
    import { AngularFireFunctions} from '@angular/fire/functions'
    import { firestore } from 'firebase/app';
    import * as firebase from 'firebase/app';
import { IonCard  } from '@ionic/angular'

@Component({
  selector: 'app-feed',
  templateUrl: './feed.page.html',
  styleUrls: ['./feed.page.scss'],
})
export class FeedPage implements OnInit, AfterViewInit {
@ViewChildren(IonCard, { read: ElementRef }) cards: QueryList<ElementRef>;
sub
 postcall

 constructor(  
    private aff:AngularFireFunctions,
    public afstore: AngularFirestore,
    private afs: AngularFirestore, 
    private gestureCtrl: GestureController,
   ) {}

 
ngOnDestroy() {
    this.sub.unsubscribe()
}

  
  
 
  ngOnInit() {
   

 const postcall2 = this.aff.httpsCallable('postscall2')
  this.sub = postcall2({}).subscribe(data =>{
    this.postcall2 = data
    
    console.log("postcall2");
    console.log(this.postcall2);
  } )



 ngAfterViewInit(){

    const cardArray = this.cards.toArray()
    this.useLonpress(cardArray)
  }


 useTinderSwipe(cardArray) {
       for (let i = 0; i < cardArray.length; i++){
         const card = cardArray[i];
         console.log('card', card)
         const gesture = this.gestureCtrl.create({
           el: card.nativeElement,
           gestureName: 'swipe',
           onStart: ev => {

           },
           onMove: ev => {
            
            card.nativeElement.style.transform = `translateX(${ev.deltaX}px) rotate(${ev.deltaX / 10}deg)`;

           },
           onEnd: ev => {
           card.nativeElement.style.transition = '3.5 ease-out';
             if(ev.deltaX > 175){
              card.nativeElement.style.transform = '';
             console.log("do something")
             this.presentToast()

             }else if (ev.deltaX < -175) {
              card.nativeElement.style.transform = '';
              console.log("do something else")
              this.presentToast1()

             }else{
               card.nativeElement.style.transform = '';
               
             }
           }
         });
         gesture.enable(true)
       }
     }

}

If you have any insights on how to resolve this issue, please share. Don't forget to upvote so others can benefit from it as well. Thank you in advance!

Answer №1

Revamp your template:

<img class="map" [src]="picToDisplay" (click)="alterView()"></img>

Also, define a variable within the class:

picToDisplay:string="https://ucarecdn.com/{{postsinfo.postviewID}}/-/preview/{{postsinfo.style}}";  // always initialize with a correct value

Modify alterView method:

alterView(){
          this.picToDisplay=.....
  }

OR

I am seeking guidance on how to achieve the layout of the first image while showcasing multiple products on the card!

My code snippet is as follows:

https://i.stack.imgur.com/c02Wb.png

Answer №2

Encountered a similar issue and discovered that when dealing with dynamically loaded elements (such as from Firebase), it's important to use ngAfterViewChecked() instead of ngAfterViewInit(). This ensures that the data is ready before manipulating it.

By making this simple adjustment, you should find that everything functions smoothly without any hiccups.

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

Is there a way to upgrade Angular from version 15 to 16 without encountering issues with ESBuild getting blocked and causing the update to fail?

I have been attempting to upgrade Angular from version 15 to version 16. However, when I execute the command ng update @angular/core@16 @angular/cli@16, it initiates the update process but at a certain point, "ESBuild.exe" is triggered and my "ThreatLocker ...

What's the process for validating i18n dictionaries using TypeScript?

Is there a way to enforce type checking on existing keys within dictionaries in react-i18next? This means that TypeScript will provide warnings at compile time if a key does not exist. For example: Let's say we have the following dictionary: { "f ...

Ensuring robust type safety when using various maps and multiple enums as their keys

I am working on creating a type-safe function for retrieving values from a map. The function needs to handle specific logic in my use case, which is why I require it beyond this simple example below: enum ExampleA { A = 'A' } enum ExampleB { ...

Retrieving URLs of bulk uploaded images using ReactJS and Firebase

I am facing an issue with my current state setup where I am storing an array of images. The problem arises when I try to upload each image to Firebase by iterating through the array. Despite using getDownloadURL() in each iteration, it consistently retur ...

Angular 4 - Issue with Top Navigation Bar not remaining fixed at the top of the page

I'm having trouble finding a solution to keep the top navigation bar fixed at the top of the screen without allowing it to scroll when the page becomes too long. I want to prevent the top nav bar from scrolling and maintain its position at the top of ...

Dealing with Angular error interceptor and handling multiple occurrences of 401 responses

I'm currently working on implementing a refresh token feature in my Angular frontend to handle expired access tokens. The issue I'm facing is that upon reloading the page after token expiration, multiple requests are sent to the backend simultane ...

Is it possible to eliminate a parameter when the generic type 'T' is equal to 'void'?

In the code snippet below, I am attempting to specify the type of the resolve callback. Initially: Generic Approach export interface PromiseHandler<T> { resolve: (result: T) => void // <----- My query is about this line reject: (error: a ...

You appear to be missing a dependency on either "@angular/core" or "rxjs" when attempting to deploy your MEAN app on Heroku. This issue must be resolved

I encountered an issue while trying to deploy my MEAN-stack application on Heroku. My app was built mainly following this tutorial series. However, during the deployment process by pushing to GIT, I received the following error: <a href="/cdn-cgi/l/emai ...

Preventing a page refresh in Angular 2 on an ASPX page: Strategies for success

The use of the pagemethod is successful, but I encountered an issue with the webmethod causing the page to refresh, which defeats the purpose of using Angular 2. Is there a way to prevent the form from refreshing the page? index.aspx <body> &l ...

What is the best way to retrieve the current value of an *ngFor loop upon button click?

I have been attempting to retrieve the data.login value of the data item that the user has clicked on the avatar image. Despite my efforts, I have not been able to successfully achieve this through various methods found online. How can I access the current ...

Utilizing a variety of Reactive FormGroups to manage a shared data source

My data source is structured as follows: data = { Bob: { hobbies: ['cycling', 'swimming'], pets: ['cat', 'dog'] }, Alice: { hobbies: ['cycling, 'chess'] ...

Encountering a CORS issue while attempting to make a GET request to an API in an

Looking to retrieve HTML data from a website using an API. The target URL is: https://www.linkedin.com/ Trying to fetch the HTML page as text from this specific URL. Here's what I attempted: getData() { const api = "https://www.linkedin. ...

Creating a date format for a REST API using Typegoose and Mongoose

Currently, I am utilizing TypeScript for a server that is connected to a MongoDB database. To ensure consistency, I am defining the outputs using an OpenAPI file. When working with Mongoose, I have experience in defining dates like this: birthday: Dat ...

Tips for transferring a value from a component class to a function that is external to the class in angular

Is there a way to pass a variable value from a component class to a function outside the class? I've been struggling to make it work. Whenever I click the button, I receive an error message saying "cannot read property divide of undefined". Here' ...

Redirect to a new page following a toastr notification in an Angular application

Looking for a way to automatically navigate to another page after a toastr notification disappears. showToasterWarning(){ this.notifyService.showWarning("No Data Found for this Date!", ""); } The notifyService is responsible ...

Node encountering an ENOENT error while invoking the Ffmpeg binary through the Fluent-Ffmpeg API

Scenario I am currently developing a Firebase function in Node.js. The main goal is to trim an incoming audio clip to a specific length using FFmpeg and Fluent-FFmpeg. Challenge However, I encountered an issue when the function is triggered in Firebase. ...

Blueprint for constructing an optimal Angular and Spring Boot application.Creating a streamlined process for

I am currently working on constructing a spring boot/angular application. My goal is to run it locally in order to work on the front end login/logout process. To do this, I have angular set up to run on port 4200 and spring boot running on port 8080. How ...

Regex struggles to identify words containing foreign characters

Here is a method I have created to check if a user-input term matches any blacklisted terms: static checkAgainstBlacklist(blacklistTerms, term) { return blacklistTerms.some(word => (new RegExp(`\\b${word}\\b`, 'i&ap ...

Attach a click event to image element

Exploring Ionic with Angular, I have a dynamic object in TS that contains various options. I am looking to access the value of this object on an HTML img click event. TS: showOptions = false; options = [ { id: '0', icon: 'a ...

How to automatically scroll to the most recently added element in an *ngFor loop using Angular 2

In my web page, I have a dynamic list rendered using an ngFor loop. Users can add or remove elements from this list by clicking on a button. What I want to achieve is to automatically scroll the browser view to the latest element added when a user clicks o ...