I need to get a variable inside this function
this.rooms.subscribe(
function (x) {
y= x[0].id;
alert(y)
});
but when it accesses it out of the function it returns to its initial value
here the whole code:
openChat(cid, nome) {
let y = ''
this.rooms = this.db.collection<roomMembers>
('room-members', ref => ref.where('uid', '==', this.uid).where('uidOutro', '==', cid)).valueChanges();
this.rooms.subscribe(
function (x) {
y = x[0].id;
alert(y)
}
);
alert(y)
this.navCtrl.push(Chat, {
uid: cid,
nome: nome,
id: y
});
}