Reputation: 23
i'm trying to display the names of my users in a list using angularjs. already tried to look for an answer in the docs.
"users" : {
"simplelogin:24" : {
"age" : "24",
"email" : "[email protected]",
"gender" : "male",
"location" : "USA",
"name" : "IY"
},
"simplelogin:25" : {
"age" : "21",
"email" : "[email protected]",
"gender" : "female",
"location" : "USA",
"name" : "iris"
}
}
here what i'm trying to do:
var app = angular.module('myApp.home', ['firebase.auth', 'firebase', 'firebase.utils', 'ngRoute']);
app.controller('HomeCtrl', ['usersList','$scope', 'fbutil', 'user', '$firebaseObject', 'FBURL',
function (usersList, $scope, fbutil, user, $firebaseObject, FBURL) {
$scope.syncedValue = $firebaseObject(fbutil.ref('syncedValue'));
$scope.user = user;
$scope.FBURL = FBURL;
$scope.users = usersList;
}]);
app.factory('usersList', ['fbutil', '$firebaseArray',
function(fbutil, $firebaseArray) {
var ref = fbutil.ref('users').limitToLast(50);
return $firebaseArray(ref);
}]);
and:
<ul><li ng-repeat='user in users'>{{user.name}}</li></ul>
Upvotes: 0
Views: 530
Reputation: 4978
Most basic way to get the users and show them:
var app = angular.module('myApp.home', [])
app.factory('usersList', function(fbutil, $firebaseArray) {
//Get the firebase reference
var ref = fbutil.ref('users');
//return the array of users
return $firebaseArray(ref);
});
app.controller('HomeCtrl', function (usersList, $scope) {
//Put the users array in the scope.users
$scope.users = usersList;
});
And the ng-repeat just stays the same.
Upvotes: 1
Reputation: 891
Since you didn't put an angularJS code, I don't know how to fix your code.
However, I can inform about 'how to display the name property of firebase object.'
var ref = new Firebase(your firebase url);
var userOne = $firebaseObject(ref.child('users').child('simplelogin:24'));
userOne.$loaded(function(){
console.log(userOne.name);
});
var userTwo = $firebaseObject(ref.child('users').child('simplelogin:25'));
userTwo.$loaded(function(){
console.log(userTwo.name);
});
I hope this code is what you wanted.
And, you have read the doc of angularFire?
https://www.firebase.com/docs/web/libraries/angular/api.html
Give it a try!
Upvotes: 0