Getting started with Single Page Apps
How to start using AngularJS to create single page applications, and the difference between the level of code here and the previous example
by Jonathon Mascorella
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<div ng-controller="messages" class="col-xs-12">
<div class="form-group">
<input class="form-control" ng-model="query">
</div>
<ul class="list-group">
<li ng-show="query.length > 3" ng-repeat="user in users | filter: query">{{user.firstName}} {{user.lastName}}</li>
</ul>
</div>
JavaScript
//An introduction to Single Page Applications
//
//AngularJS - a basic intro
var myApp = angular.module('csMessages',[]);
myApp.factory('messageService', ['$rootScope', '$http', function($rootScope, $http) {
return {
get_user_table : function() {
var url = "https://api.mongolab.com/api/1/databases/angularjs-intro/collections/users?apiKey=terrPcifZzn01_ImGsFOIZ96SwvSXgN9";
return $http.get(url);
}
};
}]);
myApp.controller('messages', ['$scope', 'messageService', function RetrieveAndStore($scope, messageService) {
messageService.get_user_table().then(function(result) {
$scope.users = result.data;
console.log($scope.users);
});
}]);