One to many firebase using firebase util

Posted: September 30, 2015 in web

Service

function getTopics(id) {
                var fb = new Firebase(REST_BASE);
                var norm = new Firebase.util.NormalizedCollection(
                        [fb.child('topics/'+id), 'topic'],
                        [fb.child('users'), 'users', 'topic.user']);
                norm = norm.select('topic.user', 'topic.date', 'topic.msg', 'users.imgPath', 'users.name', 'users.type');
                return norm.ref();
            }

DB

topics
 topic1
 32
 date: 
"sdf"
 msg: 
"ffff"
 user: 
45
 123
 date: 
"asdf"
 msg: 
"dsfsdf"
 user: 
45


Users
45
 imgPath: 
"f.png"
 name: 
"sdfsdf"
 type: 
"fb"

Controller


var ref = topicService.getTopics('topic1');

        ref.on('value', function (snap) {
            $scope.topicList = snap.val();
        });

Template

<a ng-repeat="item in topicList" class="item item-avatar" href="#">
                <img src="img/noavatar.png">
                <h2>{{item.userid}}</h2>
                <p>{{item.msg}}</p>
            </a>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s