gpt4 book ai didi

javascript - 将函数参数传递给 $scope.$apply?

转载 作者:数据小太阳 更新时间:2023-10-29 04:08:15 24 4
gpt4 key购买 nike

我正在使用 $scope.$apply 进行回调,特别是 Stripe。目前我有一些代码,比如

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);
});
};

这个问题是我无法获得 stripeCallback 的任何参数,即 response。有什么方法可以将函数参数传递给 $scope.$apply 吗?我一直没能找到任何对此的引用是文档。

最佳答案

stripeCallback包装成一个匿名函数:

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);
});
});
};

关于javascript - 将函数参数传递给 $scope.$apply?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16991323/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com