I am trying to get data from Firebase. I do practices to learn Firebase better and my app is like a message app.
My problem is, that I try to get these message data, but because they have a unique id, I can't reach them. How can I reach messagecontents,dates?
Here is my database structure:
angularish
-> <id>
-> "sender" : "john"
-> "to" : "sarah"
-> "date" : "16/09/2016"
-> "messageContent" : "Something like a long text..."
-> <id>
-> "sender" : "john"
-> "to" : "sarah"
-> "date" : "16/09/2016"
-> "messageContent" : "Something like a long text..."
-> <id>
-> "sender" : "john"
-> "to" : "sarah"
-> "date" : "16/09/2016"
-> "messageContent" : "Something like a long text..."
Here is my code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test3 Angular</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.4.1/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.4.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.4.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.4.0/firebase-database.js"></script>
<!-- Leave out Storage -->
<!-- <script src="https://www.gstatic.com/firebasejs/3.4.0/firebase-storage.js"></script> -->
<script>
// Initialize Firebase
firebase.initializeApp(config);
</script>
<script>
var app2 = angular.module("theapp",[]);
app2.controller("generalController",function($scope){
var database = firebase.database();
var rootRef = database.ref();
var subRootRef = rootRef.child("angularish");
$scope.messages = [];
rootRef.push({
"sender":"y",
"to" : "x",
"messageContent" : "Something like a long text",
"date" : "10/06/2016"
});
rootRef.on("value",function(snapshot){
$scope.messages = snapshot.val();
console.log(snapshot.val());
});
});
</script>
</head>
<body>
<div class="container" ng-app="theapp" ng-controller="generalController">
{{ 1+1 }}
<ul>
<li ng-repeat="message in messages">
{{ message.messageContent }}
</li>
</ul>
</div>
</body>
</html>
startAtandendAtfirebase.google.com/docs/database/web/… Heres an example jsfiddle.net/katowulf/vQEmt/2