gpt4 book ai didi

javascript - 如何在 script 标签中使用 AngularJS?

转载 作者:行者123 更新时间:2023-12-02 16:41:20 24 4
gpt4 key购买 nike

我想将 Angular 与 Stripe 支付模式结合使用。脚本标签中没有分配任何价格变量。有没有办法用 Angular 来做到这一点?

HTML

<div ng-app="app">
<div ng-controller="ctrl">
<form action="" method="POST">
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button" data-key="pk_test_" data-amount={{price}} data-name="Example Product" data-description="Example Product {{price}}" data-image="/128x128.png">
</script>
<br>Price ${{price}}
</form>
</div>
</div>

Angular :

var app = angular.module('app',[]);

function ctrl($scope) {
$scope.price = "77";
}

示例:http://jsfiddle.net/ppq1orso/

最佳答案

您可以在 Controller 中设置属性,而不是使用脚本标记

您必须添加自定义按钮

 <button type="submit" ng-click="pay()" class="stripe-button-el" style="visibility: visible;"><span style="display: block; min-height: 30px;">Pay with Card</span></button>  

在 Controller 中:

 var handler = StripeCheckout.configure({
image: "https://stripe.com/img/documentation/checkout/marketplace.png",
key:'pk_test_'
});

$scope.pay = function(){
handler.open({
name: 'Example Product',
description: 'Example Product ' + $scope.price,
amount: $scope.price * 100
});
e.preventDefault();
};

这按预期工作:

http://jsfiddle.net/ppq1orso/3/

关于javascript - 如何在 script 标签中使用 AngularJS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27471613/

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