我無法弄清楚爲什麼範圍變量沒有被分配。
<script src="https://js.paystack.co/v1/inline.js"></script>
<button type="button" ng-click="checkout()">Checkout</button>
<div ng-show='txref'>
<h2>Payment successful!</h2> Transaction reference: {{txref}}
</div>
JS
//this function triggers when the button above is clicked. Everything else except assigning the reference to $scope.txref
$scope.checkout = function() {
var handler = PaystackPop.setup({
key: 'pk_test_1c828c1b8d9a98232c90d7aa6c418953c8150096',
email: '[email protected]',
amount: 10000 * 100,
ref: Math.floor((Math.random() * 100000) + 1),
callback: function(response){
console.log(response.reference) //works
alert(response.reference) //works
$scope.txref = response.reference; //doesn't work until you click the button again
},
onClose: function(){
alert('window closed');
}
});
handler.openIframe();
}
回調一切正常,除了分配參考$ scope.txref。它拒絕工作,但是當你再次點擊按鈕時,一切都是正常的。我不知道什麼是錯的。
初始化txref。 '$ scope.txref ='';' – taguenizy