Last active
August 6, 2020 03:56
-
-
Save jeffdonthemic/7247654 to your computer and use it in GitHub Desktop.
Passing parameters in an Angular.js Controller to a Resource
This file contains 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
<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} } | |
}); | |
} | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very helpful thanks.