I've been trying to make a pretty and user friendly app in angular and i'm at the part where i let the user know stuff is loading when i make ajax requests. What i'm trying to accomplish : i want to create a service that handles the initialization data fetching and pass the data as an object to my controller when it becomes available. Of course, the view isn't displayed until all the initial data my controller needs is available. Here's what i have so far:
app.js
var Application = angular.module('ReporterApplication', ['ngRoute']);
Application.service('Initialize', ['$http', '$q', '$timeout', function($http, $q, $timeout)
{
this.serverData = function()
{
$http.get('/packing/scan.action')
.success(function(data)
{
return data;
})
.error(function(data)
{
return data;
});
};
}])
Application.config(['$routeProvider', '$interpolateProvider',
function($routeProvider, $interpolateProvider) {
$interpolateProvider.startSymbol('<%');
$interpolateProvider.endSymbol('%>');
$routeProvider
.when('/packing/scan.html', {
templateUrl: 'packing/scan.html',
controller: 'PackingScanController as packer',
resolve: {
initData : 'Initialize' .... etc more code
scan.js
Application.controller('PackingScanController', ['$scope', '$http', 'initData', function($scope, $http, initData) {
var packer = this;
packer.packedToday = initData.serverData(); ... etc more code