A very rookie-ish question:
I'm trying to build resource object using factory method:
.factory('Magazines', [function ($resource) {
var url = document.URL;
var urlArray = url.split("/");
var organId = urlArray[urlArray.length-1];
return $resource('http://localhost/ci/api/magazines/:id', {
loginID : organEntity,
password : organCommpassword,
id : organId
});
}])
This method is easy because all params are predefined, organEntity and organCommpassword are defined inside tag.
Now for a different resource object, I need to pass in parameter when the factory is called.
I imagine the calling code of this resource object should look like:
.controller('ResrouceCtrl', function($scope, Magazines) {
$scope.magazines = Magazines.query();
});
I know query() method can add parameters: Magazines.query(params, successcb, errorcb);
I wonder if I just pass in parameters, can I get the parameter at the factory? How to specify such passed in parameters in the factory method?
For example, now suppose I cannot get organId from url anymore, I need to pass it in from my controller, how to receive organId within the factory method?
Here is my resource js:
.factory('MagComments', function ($resource) {
return $resource('http://localhost/dooleystand/ci/api/magCommenct/:id', {
loginID : organEntity,
password : organCommpassword,
id : '@magId' //pass in param using @ syntax
});
})
Here is my controller:
$scope.magComments = MagComments.query({magId : 1});
I tried to pass in the parameter, but it causes an error
See Question&Answers more detail:
os