Currently having trouble understanding the problem with my following piece of code. Any advices or informations are more than welcome!
getProjects(client):string[] {
client = client.trim();
var tempProjects = [];
// if(this.m_projects.length >= 1){
// this.m_projects = [];
// this.m_tasks = [];
// this.sTask = null;
// this.sProject = null;
// }
const curTaskObservable = this.afs.collection('users').doc('myFirstUser')
.collection('clients').doc(client).collection('projects')
.valueChanges()
.subscribe((data:any)=>{
data.forEach(el=>{
if(this.m_projects.indexOf(el.name) === -1){
this.m_projects.push(el.name);
tempProjects.push(el.name);
}
});
});
console.log("array length : " + tempProjects.length);
console.log(" array content : " + tempProjects);
return tempProjects;
The output, as shown below prints the length "0" and for the array content, the length "1". How can that be possible, and is there a way to get the correct length value. Thank you!