I have an array. I am running to issues, so...
In my code, I placed the following debugging code:
console.log(this.pages);
console.log(this.pages.length);
The output in Chrome's debug window is like the following. You will see the first one shows a length: 38 but the second console.log shows 0. Why does the second one not show 38 also?
import { Injectable } from '@angular/core';
import { AngularFire, FirebaseListObservable } from 'angularfire2';
@Injectable()
export class SitemapService {
pagesObservable: FirebaseListObservable<any[]>;
pages: any[] = [];
data: string = '';
constructor(
protected af: AngularFire,
private datePipe: DatePipe,
private urlPipe: UrlPipe
){
this.pagesObservable = this.af.database.list('/pages', {
query: {
orderByChild: 'sortOrder',
limitToLast: 100
},
preserveSnapshot: true
})
this.pagesObservable.subscribe(snapshots => {
snapshots.forEach(snapshot => {
this.pages.push(JSON.stringify(snapshot.val()));
})
})
}
getSitemapData(): string {
let urlBase = location.protocol + '//' + location.host;
console.log(this.pages);
console.log(this.pages.length);
return (this.data);
}
}