I am a beginner in Angular and JavaScript in general. While working on building a prototype app using examples and tutorials, I have encountered a simple issue that involves passing parameters.
My goal is to receive a parameter (myKey) in my controller and pass it to a factory which will then use it for a web API request. I have tried using a constant for myKey in the factory, but I'm struggling with passing it as a parameter.
I apologize for the basic question and acknowledge that I have more studying to do.
Thank you
'use strict';
/* Factories */
angular.module("myApp.myViewer.factories", []).factory('myThings', ['$resource',
function ($resource) {
var resource = $resource('/api/myThings', {}, { get: { method: 'GET', params: { myKey:"M1234" } } });
return resource;
}
]);
/* Controllers */
angular.module("myApp.myViewer.controllers", [])
.controller('myCtrl', ['$scope', 'myThings', function ($scope, myThings) {
myThings.get(function (response) {
console.log(response);
$scope.myThing = response;
});
}]);