Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

290
Views
How to unsubscribe from observable in Angular in for loop?
const sub1 = this.angularFirestore.collection('Date').doc('username).collection('time').snapshotChanges();

const sub2 = await sub1.subscribe((snapData: DocumentChangeAction<any>[]) => {
`
// After each minute, new data is inserted in firebase storage, and the below
// code runs automatically, because I have subscribed to it.
// now the problem is, after 1 minute, snapData has duplicate records
// and for loop is also executed.
// method for getting URL from firebase storage, called from below for loop`
 const send = storageRef =>
        new Promise(resolve => {
            storageRef.getDownloadURL().then(url => {
                resolve(url);
              }, err => {
              }
            );
          }
        );
   for (const d of snapData) {
          const storageRef = 
         firebase.storage().ref().child(d.payload.doc.data().timeEachMinute);
                const ImgUrl = await send(storageRef);
                this.timestampsList.push({
                  dateObj: d.payload.doc.data().dateObj,
                  imageUrl: ImgUrl,
                  date: d.payload.doc.data().screenShot,
                  name: d.payload.doc.data().user
                });

      }
}
sub2.unsubscribe();

For example, I am retrieving 1000 records, which may not be completed in one minute, suppose 500 records are retrieved, after one minute, new records start fetching from start as well as 501 onward, which lead to duplicate records. Now i am confused whether the problem is in for loop or observer subscription.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!