Currently, I am engaged in a project using Angular2 and Firebase.
My goal is to consolidate all query results under a single key called this.guestPush
.
Within my project, there is a multiple select element with different user levels - specifically 4, 6, and 9.
The issue arises when I select one level, as the resulting object gets saved in the guestPush
array. However, upon selecting another level, an error occurs:
The error message displayed is as follows:
ERROR TypeError: this.guestPush[("filter" + i)].push is not a function
Below you can see the relevant code snippet:
guestPush: any[] = new Array;
level.forEach((lvl, index) => {
this.db.object(`levelsUsers/${lvl}/users`)
.subscribe(users => {
if (this.guestPush['filter_' + i]) {
this.guestPush['filter_' + i].push(users);
} else {
this.guestPush['filter_' + i] = users;
}
}, err => console.log(err));
});
Edit:
The 'users' object comprises user entries that match the filter criteria:
Object {-KmSjAaxdCUvrPEQ8InI: Object, $key: "users", $exists: function}
-KmSjAaxdCUvrPEQ8InI: Object
admin:"false"
description:"desc"
...
...
verified:false
__proto__:Object
exists:function ()
$key:"users"
__proto__:Object
By executing this.guestPush[i] = users;
, an object like the following is generated:
[Object]
0:Object
-KmSjAaxdCUvrPEQ8InI: Object
admin:"false"
description:desc"
...
...
verified:false
__proto__:Object
$exists:function ()
$key:"users"
__proto__:Object
length:1
__proto__:Array(0)
Hence, moving forward, I aim to append any new user objects alongside -KmSjAaxdCUvrPEQ8InI
, or any other value under the 0
key.