I've been attempting to utilize AngularJS to organize my data, but unfortunately, it seems to be ineffective.
I am fetching data from Firebase () and using Node.js to transmit it to a controller.
Controller Code
var myApp = angular.module('myApp', []);
myApp.controller('AppCtrl', ['$scope', '$http', function($scope, $http) {
// Pulls list of games
$scope.pullGame = function() {
console.log("Here");
$http.get('/getGameData').success(function(response) {
console.log(response);
$scope.championlist = response;
});
};
}]);
Then I am displaying the information using ng-repeat
<!DOCTYPE>
<html ng-app="myApp">
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
<title>DevCha</title>
</head>
<body>
<div class="container" ng-controller="AppCtrl">
<input class="form-control" ng-model="game.name">
<button class="btn btn-info" ng-click="pullGame()">Update</button>
<h1>DevCha</h1>
<table class="table">
<thead >
<tr>
<th>Champion Name</th>
<th>Wins</th>
<th>Losses</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="champion in championlist|orderBy: 'name'">
<td>{{champion.name}}</td>
<td>{{champion.wins}}</td>
<td>{{champion.losses}}</td>
</tr>
</tbody>
</table>
</div>
<script src="controllers/controller.js"></script>
</body>
</html>
I have attempted to use Firebase to sort the data without success, which is strange. I am open to either Angular or Firebase helping me sort the data.
Node.js code that sends the data to Angular
app.get('/getGameData', function(req, res){
var ref = new Firebase("https://boiling-inferno-4886.firebaseio.com/champion");
ref.once("value", function(snapshot) {
// Success
console.log(JSON.stringify(snapshot.val()));
res.json(snapshot.val());
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
//callback("Failure", null);
});
});
Sample_Data - 1: {name: 'Jim', Wins: 10, Losses: 5}, 2: {name: 'Fred', Win:8, Losses: 5} (Actual data can be found at the firebase link)
tl:dr I need to sort my data, I have tried using Firebase's built-in methods and Angular's | orderBy, but neither are working