Hi, I do it this way: My Controller:
$scope.resyncToken = function() {
TokenFactory.resync({serial: $scope.tokenSerial,
otp1: $scope.otp1,
otp2: $scope.otp2}, function (data) {
$scope.otp1 = "";
$scope.otp2 = "";
$scope.resultResync = data.result.value;
$scope.get();
});
};
and the Factory looks like this:
angular.module("TokenModule", ["privacyideaAuth"])
.factory("TokenFactory", function (auth, $http, $state, $rootScope,
tokenUrl) {
/**
Each service - just like this service factory - is a singleton.
*/
var user = auth.getUser();
var auth_token = auth.getAuthToken();
var error_func = function (error) {
if (error.result.error.code == -401) {
$state.go('login');
} else {
$rootScope.restError = error.result;
}
};
return {
resync: function (params, callback) {
$http.post(tokenUrl + "/resync", params,
{
headers: {'Authorization': auth_token}
}).success(callback
).error(error_func)
}
}
});
I.e. I gather all scope parameters into a params object and pass the
params object, which in fact are the parameters that are passed with the
post request.
Kind regards
Cornelius
Am 12.01.2015 um 17:30 schrieb Ihab Assi:
> I have a factory that run facebook share function and I was able to
> make it send back the result to the controller when calling it.
>
> The thing is that I need to pass an arguments to the factory.
>
> How can I dot it?
>
> Thanks
> Ihab
>
> This is my factory code:
>
> appServices.factory('FbShare', function() {
> var run = function(callback) {
> var pic = g_app_link + 'uploads/covers/ihab.png'; // + p_pic;
>
> var obj = {
> method: 'feed',
> link: g_app_link + 'redir.php',
> picture: pic,
> name: g_share_txt,
> caption: g_share_caption
> };
>
> FB.ui(obj, function(response) {
> callback(response);
> });
> };
>
> return {
> run: run
> };
>
> });
>
> And this is how I call it from the controller:
>
> $scope.shareOnTimeline = function (p_pic) {
> FbShare.run(function(response) {
> if (response && !response.error_code) {
> console.log('shared');
> } else {
> // this option just in case we need a deffirent behaviour
> when not shared
> console.log('share cancled');
> }
> });
> };
>
> --
> You received this message because you are subscribed to the Google
> Groups "AngularJS" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected]
> <mailto:[email protected]>.
> To post to this group, send email to [email protected]
> <mailto:[email protected]>.
> Visit this group at http://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
signature.asc
Description: OpenPGP digital signature
