0

My lists are only populated when I manually enter in static values for the variables, not when I get them from the forEach loop.

TypeScript

this.pinnedCCollection = this.afs.collection(pinnedCollection);
this.pinnedC = this.pinnedCCollection.valueChanges().do(item => {
    console.log('-------------');

    item.forEach(element => {

      // NOT WORKING
      // this.searchedS = element.s;
      // this.selectedT = element.t;
      // this.selectedC = element.c;

      // WORKING
      this.searchedS = 'static value 1';
      this.selectedT = 'static value 2';
      this.selectedC = 'static value 3';

      this.searchForA();  
    });

  });

searchForA(){
    var placeToSearch = 'SPlace/'+this.searchedS+'/TPlace/'+this.selectedT+'/CPlase/'+this.selectedC+'/APlace';

    this.aCollection = this.afs.collection(placeToSearch);
    this.a = this.aCollection.valueChanges();
 }
9
  • what is the type of item ? can you add a sample data ? Commented Nov 10, 2017 at 20:42
  • forEach((element: TypeOfElement) => ... Commented Nov 10, 2017 at 20:44
  • Niether of the variables item or element have types. Do I need it? Commented Nov 10, 2017 at 21:05
  • whats the structure of items? if they're objects you can't iterate them with forEach like they're an array? what's the specific error you're getting Commented Nov 10, 2017 at 22:06
  • I'm already iterating over each item with forEach, and I'm able to successfully log out the value of those elements inside of forEach and they are successfully saved into my local variables. Then searchForA() runs with the proper values in place, but the list on my webpage still comes up empty. The values from the properties of element seem to be perfectly fine. Commented Nov 10, 2017 at 22:15

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.