Braintree javascript client-Teardown调用不会删除托管字段上现有的integration-gettings错误
我目前正在尝试将braintree集成到我的angularJS web应用程序中,我面临以下问题 当用户选择执行付款时,我会打开一个模式来显示我的付款表单。在modal的控制器中,我首先运行Braintree javascript client-Teardown调用不会删除托管字段上现有的integration-gettings错误,javascript,angularjs,braintree,teardown,Javascript,Angularjs,Braintree,Teardown,我目前正在尝试将braintree集成到我的angularJS web应用程序中,我面临以下问题 当用户选择执行付款时,我会打开一个模式来显示我的付款表单。在modal的控制器中,我首先运行braintree.setup(…)函数。我在表单中使用托管字段。一切正常(提交测试卡号并成功返回nonce),但当我关闭模式然后重新打开时,我使用的托管字段出现以下错误: Object {message: "Cannot place two elements in "#card-number""} Obje
braintree.setup(…)
函数。我在表单中使用托管字段。一切正常(提交测试卡号并成功返回nonce),但当我关闭模式然后重新打开时,我使用的托管字段出现以下错误:
Object {message: "Cannot place two elements in "#card-number""}
Object {message: "Cannot place two elements in "#cvv""}
Object {message: "Cannot place two elements in "#expiration-month""}
Object {message: "Cannot place two elements in "#expiration-year""}
我尝试使用提供的teardown方法(如文档中所示),但仍然会出现错误
在modal的控制器中,当我从服务器获得令牌时,我调用函数$scope.setupBraintree($scope.token)
<代码>$scope.setupBraintree的定义如下:
$scope.setupBraintree = function(token){
braintree.setup(token, "custom", {
id: "paymentForm",
hostedFields: {
number: {
selector: "#card-number"
},
cvv: {
selector: "#cvv"
},
expirationMonth: {
selector: "#expiration-month"
},
expirationYear: {
selector: "#expiration-year"
}
},
onReady: function(integration){
$scope.checkout = integration;
}
});
};
$scope.cancel = function() {
$scope.checkout.teardown(function () {
$scope.checkout = null;
// braintree.setup can safely be run again!
});
$uibModalInstance.dismiss('cancel');
};
然后,当用户关闭模式时,将调用$scope.cancel(),其定义如下:
$scope.setupBraintree = function(token){
braintree.setup(token, "custom", {
id: "paymentForm",
hostedFields: {
number: {
selector: "#card-number"
},
cvv: {
selector: "#cvv"
},
expirationMonth: {
selector: "#expiration-month"
},
expirationYear: {
selector: "#expiration-year"
}
},
onReady: function(integration){
$scope.checkout = integration;
}
});
};
$scope.cancel = function() {
$scope.checkout.teardown(function () {
$scope.checkout = null;
// braintree.setup can safely be run again!
});
$uibModalInstance.dismiss('cancel');
};
因此,当我希望braintree集成被销毁时(当modal关闭时),我调用teardown方法。当我关闭模式时,$scope.checkout
确实为空(这意味着按预期运行拆卸),但是当我再次打开模式时(并且再次向服务器执行新请求以获取客户端令牌)我得到了关于托管字段的上述错误,因此我想知道我是否遗漏了一些内容,或者托管字段上是否存在任何拆卸问题
谢谢你的帮助,
巴比斯(Babis)用拆卸法一切都很好。问题是在模式上注册的事件被触发了两次,因此安装程序在模式第二次打开时运行了两次 修复了每次模式加载时,设置功能都会平稳运行,并且拆卸工作正常的问题