Home>
I want to create a chat app using ionic x firebase.
An error will occur in the following part.
I was able to confirm that the data could be obtained from the firebase DB.
I am in trouble because I do not know the cause of the error.
Thank you.
[Error message]
ERROR TypeError: Cannot read property'rooms' of undefined
at room.page.ts: 33
at DataSnapshot.js: 126
at LLRBNode.push ../node_modules/@firebase/database/dist/cjs/src/core/util/SortedMap.js.LLRBNode.inorderTraversal (SortedMap.js: 170)
at LLRBNode.push ../node_modules/@firebase/database/dist/cjs/src/core/util/Sorte
export class RoomPage implements OnInit {
rooms = new Array ();
constructor (public navCtrl: NavController) {}
async ngOnInit () {
firebase.auth (). onAuthStateChanged ((user) =>{
if (user) {
firebase.database (). ref ('chatrooms /'). on ('value', function (resp)
{
if (resp) {
console.log ("firebase.database (). Ref ()");
//this.rooms = new Array ();
resp.forEach (function (child snapshot)
{
const room = childsnapshot.val ();
room.key = childsnapshot.key;
this.rooms.push (room);// * Where the error occurred
return false;
});
}
});
} else {
this.navCtrl.navigateRoot ('signin');
}
});
}
-
Answer # 1
Related articles
- typescript associative array call results in error
- java - i get an error when using an array when instantiating
- when deploying in firebase, i get an error that @ typescript-eslint is not unique
- the type defined by the typescript interface causes an error
- array error in fortran function
- error when using proxy in typescript
- java - an error occurs in the element part of the array and it does not resolve
- i get an error when i use typescript map
- syntax error occurs in nextjs + typescript
- typescript - error not finding entity metedata in tyoeorm
- javascript - [typescript] i can't write the type definition of an array with a variable length at the front
- i don't get a compile error with vscode, but i get a warning typescript
- javascript - i want to resolve the typescript error that appears in the onclick event of the progress element
- typescript - data communication segment error
- react typescript type error when updating state
- python expected 1d or 2d array, got 3d array instead error in function creation
- typescript (visual studio) to type an image and make it an array without using any
- typescript react type error
- typescript - somehow error in usereducer
Related questions
- javascript - how to eliminate can not find'fb' error
- javascript - how can ionic make body and script tags work?
- typescript - i want to automatically set a character string in ion-input with ionic × protractor
- http - i'm having trouble with post using ionic (angular)!
- typescript - how to open a modal and refresh the page when it comes back
- java - send data in json format but cannot receive it as a json string
- typescript - i want to count the number of documents of firebase cloud firestore only for last month
- javascript - i don't know how to specify and retrieve nested object types
- typescript - i want to fix tabs when scrolling with ionic4
forEach
amongfunction
Is used, but in this case in the callback functionthis
Isundefined
It will be.Let's write with an arrow function.