admin管理员组文章数量:1245083
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.
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.
2 Answers
Reset to default 7Wrap 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();
});
本文标签: javascriptPassing function arguments to scopeapplyStack Overflow
版权声明:本文标题:javascript - Passing function arguments to $scope.$apply? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740220904a2243784.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论