Created
August 25, 2013 13:44
-
-
Save Nek-/6333905 to your computer and use it in GitHub Desktop.
Angular resolve http
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated by CoffeeScript 1.6.3 | |
(function() { | |
'use strict'; | |
var NeklandModule, ProjectDetailsController, ProjectsController; | |
NeklandModule = angular.module('nekland', ['ui.state']); | |
NeklandModule.config([ | |
'$stateProvider', '$urlRouterProvider', '$locationProvider', function($stateProvider, $urlRouterProvider, $locationProvider) { | |
$locationProvider.html5Mode(true); | |
$urlRouterProvider.otherwise('/'); | |
$stateProvider.state('projects', { | |
url: '/projects', | |
templateUrl: 'projects.html', | |
resolve: { | |
projectsData: [ | |
'$http', function($http) { | |
return $http.get('/projects.json').then(function(response) { | |
return response.data; | |
}, function(reason) { | |
return false; | |
}); | |
} | |
] | |
}, | |
controller: ['$scope', 'projectsData', '$state', ProjectsController] | |
}).state('projects.details', { | |
url: '/{slug}', | |
views: { | |
'description': { | |
templateUrl: 'details.html', | |
controller: ['$scope', '$stateParams', ProjectDetailsController] | |
} | |
} | |
}); | |
} | |
]).run([ | |
'$rootScope', '$state', '$stateParams', function($rootScope, $state, $stateParams) { | |
$rootScope.$state = $state; | |
$rootScope.$stateParams = $stateParams; | |
} | |
]); | |
ProjectsController = function($scope, projectsData, $state) { | |
return $scope.projects = projectsData; | |
}; | |
ProjectDetailsController = function($scope, $stateParams) { | |
var project, _i, _len, _ref, _results; | |
_ref = $scope.projects; | |
_results = []; | |
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |
project = _ref[_i]; | |
if (project.slug === $stateParams.slug) { | |
_results.push($scope.project = project); | |
} | |
} | |
return _results; | |
}; | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment