I am working on an ionic app that loads data from firebase. In this case I have a .factory called NoteStore that reads a specific table in firebase (eg "lakes").
{
"lake": {
"one": {
"bio": "xxxx",
"shortname": "xxxx",
"name": "xxxxx",
"reknown": "xxxx",
"image":"xxxxx"
},
"two": {
"bio": "xxxx",
"shortname": "xxxx",
"name": "xxxxx",
"reknown": "xxxx",
"image":"xxxxx"
}
}
}
This is the .factory code that reads from firebase:
//get all lake activites
getAllLakes: function(){
return $firebaseArray(ref.child('lake'));
},
//get individual lake activites
getLake: function(lakeId){
return $firebaseObject(ref.child('lake').child(lakeId));
}
My app Controller then gets the data through the NoteStore and calling a function "getAllLakes():
app.controller('LakeActivitiesListController', function($scope, NoteStore, $localStorage) {
$scope.alllakes = NoteStore.getAllLakes();
}
The main problem is that I want to access individual objects from the "lake" table in firebase so that I can be able to store them in localStorage.
This then displays array of objects as below:
When I just create an object as shown below and save to localStorage, it works fine, as shown in the image below.
var myObj = [
{
name: 'james',
title:'doctor'
},
{
name: 'jojo',
title:'doctor'
}
];
console.log(myObj);
//
window.localStorage['lakes'] = JSON.stringify(myObj);
$scope.data = JSON.parse(window.localStorage.getItem('lakes'));
I am working on my college project that is overdue. Please help. All I want is to be able to access an array that contains objects from firebase so that I can store them in localStorage. Please.
var lakeData = alllakes.getAllLakes(); var data = {}; data = lakeData; for ( var i = 0; i < data.length; i++) { var obj = data[i]; console.log(obj); }
– user3225573 Apr 14 at 18:12