Skip to content

Instantly share code, notes, and snippets.

@jeffdonthemic
Last active August 6, 2020 03:56
Show Gist options
  • Save jeffdonthemic/7247654 to your computer and use it in GitHub Desktop.
Save jeffdonthemic/7247654 to your computer and use it in GitHub Desktop.
Passing parameters in an Angular.js Controller to a Resource
<script>
// in the html page
angular.module('config', []).constant('APIKEY',''5250738f97ce29c219000011'');
</script>
myApp.controller('JobsCtrl', ['$scope', 'Jobs', 'APIKEY', function($scope, Jobs, apiKey) {
var promise = Jobs(apiKey).query().$promise;
// do more awesome programming
}
myApp.factory('Jobs', ['$resource', function ($resource) {
return function(apiKey){
return $resource('/someurl/:id', {id:'@id'}, {
query: { method: 'GET', headers: {'Authorization': apiKey} }
});
}
}]);
@adachenski
Copy link

Very helpful thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment