I'm using $scope.$apply for callbacks, specifically with Stripe. Currently I have some code like
var stripeCallback = function (status, response) {
if (!response.error) {
// do something
} else {
// do something else
}
};
$scope.submit = function () {
$scope.errorMessage = 'Processing...';
$scope.buttonDisabled = true;
// can't use bindings for some reason
var myForm = $('#paymentform');
Stripe.createToken(myForm, function (status, response) {
$scope.$apply(stripeCallback);
});
};
The problem with this is that I can't get any arguments to stripeCallback
, namely response
. Is there any way I can pass function arguments to $scope.$apply
? I haven't been able to find any reference to this is the documentation.
Wrap stripeCallback
into an anonymous function:
var stripeCallback = function (status, response) {
....
};
$scope.submit = function () {
$scope.errorMessage = 'Processing...';
$scope.buttonDisabled = true;
// can't use bindings for some reason
var myForm = $('#paymentform');
Stripe.createToken(myForm, function (status, response) {
$scope.$apply(function() {
stripeCallback(status, response);
});
});
};
You can also just call $scope.$apply()
after calling your callback:
Stripe.createToken(myForm, function (status, response) {
stripeCallback(status, response);
$scope.$apply();
});
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