Reputation: 1
I want to grab data from firebase and then put all gather data into a for loop for ionic content to generate buttons.
my data is
I want to be able to grab all the phones that are currently in the database and create buttons --Don't remember the right code as typing this.
so being able to grab all available phones in Ionic Framework 3.
Upvotes: 0
Views: 3645
Reputation: 1
Try this instead
data = [];
constructor(af: AngularFireDatabase...) {
this.data = [];
}
this.af.object('/FirebaseData/')
.valueChanges()
.subscribe(data => {
let arr = Object.keys(data);
this.data = [];
for (var i = 0; i < arr.length; i++) {
const object2 = Object.assign({ Key: arr[i] }, data[arr[i]]);
this.data.push(object2);
}
Upvotes: 0
Reputation: 1119
As I see, You saved all children in root.
so retrive all data,
let user_data= [];
firebase.database().ref().on('value', (snapshot) => {
let result = snapshot.value();
for(let k in result){ //"k" provides key Id of each object
user_data.push({
id : k,
name : result[k].name,
phone : result[k].phone,
});
}
});
To show data on the front view, you can listed all phones like this way
<div *ngFor="let phone of user_data" >
{{phone.phone}}
</div>
hope this answer will help you.
Upvotes: 1