I would like te pass a variable to a factory of mine, but im not quite sure how to do it, here is my code:
var app = angular.module('docFinder', []);
app.factory('docFactory', function($http) {
var url = 'http://test.example.com?queryString=searchv2&page=';
url=url+page;
var docFactory = {
async: function() {
var promise = $http.get(url).then(function (response) {
return response.data;
});
return promise;
}
};
return docFactory;
});
app.controller('docTable', function(docFactory, $scope, $filter) {
docFactory.async().then(function(d) {
$scope.providers = d;
init();
});
}
i would like to send the page from my controller to my factory so it can return my new query
thanks
You can pass the value through your async
function in your factory:
var docFactory = {
async: function(theVarThatIWantedToPass) {
var url=// stuff
url += theVarThatIWantedToPass;
}
}
Called as normal: docFactory.async(page)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With