I want my modal dialog to be blurred while Stripe Checkout is open above it, but for some reason it stays blurred even after I've closed the secondary modal.
It's best to try it in a sample plunkr
Use card "4242 4242 4242 4242" to test, with any future expiry date and CCV. Blur must disappear once stripe window is closed, but it doesn't for some reason.
This is all basic stuff and I've been using angular for at least 3 years now, just cannot figure out where is the bug this time.
Here's JS code from the aforementioned example:
angular.module('ui.bootstrap.demo', ['ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('ModalDemoCtrl', function ($scope, $modal, $log) {
$scope.open = function () {
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
});
};
});
angular.module('ui.bootstrap.demo').controller('ModalInstanceCtrl', function ($scope, $modalInstance) {
// Text is not blurred by default.
$scope.isbusy = false;
console.log('dlg scope is ', $scope.$id);
$scope.pay = function () {
// Blur the parent dialog.
$scope.isbusy = true;
console.log($scope.$id, ' marked as busy');
var handler = StripeCheckout.configure({
key: 'pk_test_hh0HjBRRI5Ak793gMgLEZEVN',
token: function(token) {
// Remove blur effect.
$scope.isbusy = false;
console.log($scope.$id, ' marked as NOT busy');
},
closed: function() {
// Remove blur effect even if user clicks close.
$scope.isbusy = false;
console.log($scope.$id, ' marked as NOT busy');
}
});
handler.open({
name: 'Enter Your Card Details',
email: '[email protected]',
});
};
});
I assume $scope.isbusy
doesn't change as expected? The stripe callback doesn't notify Angular:
StripeCheckout.configure({
// ...
token: function(token) {
// use scope apply to notify angular:
$scope.$apply(function() {
$scope.isbusy = false;
});
console.log($scope.$id, ' marked as NOT busy');
}
// ...
AngularJS otherwise has no way of knowing that a $scope
variable was changed (unless StripeCheckout
is an angular service already).
It's vital to understand angular's way of $digest
ing information. Simply put, whenever a callback from an asynchronous non-angular service is invoked, the [callback must use $scope.apply][1] if it changes the state of
$scope` variables.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments