Quiero agregar dinámicamente botones a mi ion-list desde el typescript leyendo de mi base de datos en firebase.
Éste es mi código:
export class AboutPage {
valor:any;
username:any;
to:any;
public items: Array<any> = [];
constructor(public navCtrl: NavController, public translateService:
TranslateService, private ShareService: ShareService) {
var app = ShareService.getApp();
var database = app.database();
var msj={};
auth = app.auth();
storage = app.storage();
databaseRef = database.ref().child("chat");
msgRef = database.ref().child("messages");
storageRef = storage.ref().child('chat_photos');
this.items = [{to:"michael"}];
databaseRef.on('child_added', function(snapshot) {
var touser=snapshot.child("to").val();
msj = {to:touser}
//this.items.push(msj);
});
Agregué un caso donde agrega al array a {to:michael}
y funciona correctamente, sin embargo cuando intento hacer la llamada dentro de la función de firebase (this.items.push(msj)
), me da un error que dice que no se puede acceder a la propiedad items de null.
¿Alguna idea de como solucionar esto?