Why does AngularJS ignore $scope field change?

Paul

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]',
      });

  };

});
mnemosyn

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 $digesting 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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why does AngularJS ignore $scope field change?

From Dev

why angularjs directive inherit the scope but doesn't change the scope variable?

From Dev

AngularJS - Why does $scope.$apply affect other scopes

From Dev

AngularJS: Why does my directive cannot use $scope?

From Dev

AngularJS - Why does $scope.$apply affect other scopes

From Dev

Why does Handlebars change the scope of the data we're passing to it?

From Dev

AngularJS: Can't ignore change event on an input field after user cancels with confirmation dialog

From Dev

Why does it work with $scope but not with `this`?

From Dev

Revert change on $scope variable in AngularJs

From Dev

angularJS $scope change not updating view

From Dev

AngularJS animate element on scope change

From Dev

AngularJS: Why ng-model scope's variable is not shown in inspector if input field is empty?

From Dev

Why does the backing field of my property not change its value?

From Dev

In AngularJS, how does $scope get passed to scope?

From Dev

Why a changed to a $scope field is not propagated to another field?

From Dev

Why is my AngularJS $scope not working?

From Dev

Why AngularJS $scope is not working correctly?

From Dev

Does .bind break $scope in angularjs?

From Dev

How does Module change the scope?

From Dev

Why does Git ignore these folders?

From Dev

Why does FloatToStr ignore ThousandSeparator?

From Dev

Why does setInterval() ignore errors?

From Dev

Why does GLSL ignore return?

From Dev

Why does sudo ignore aliases?

From Dev

Why does bash ignore SIGTERM?

From Dev

Why Gulp does not ignore the file?

From Dev

AngularJS Populating input field with directive but not captured in $scope

From Dev

AngularJs: Why does scope inside my directive not update when async data arrives?

From Dev

angularJS: Why does binding to scope inside a directive result in lost content of ng-repeat?

Related Related

  1. 1

    Why does AngularJS ignore $scope field change?

  2. 2

    why angularjs directive inherit the scope but doesn't change the scope variable?

  3. 3

    AngularJS - Why does $scope.$apply affect other scopes

  4. 4

    AngularJS: Why does my directive cannot use $scope?

  5. 5

    AngularJS - Why does $scope.$apply affect other scopes

  6. 6

    Why does Handlebars change the scope of the data we're passing to it?

  7. 7

    AngularJS: Can't ignore change event on an input field after user cancels with confirmation dialog

  8. 8

    Why does it work with $scope but not with `this`?

  9. 9

    Revert change on $scope variable in AngularJs

  10. 10

    angularJS $scope change not updating view

  11. 11

    AngularJS animate element on scope change

  12. 12

    AngularJS: Why ng-model scope's variable is not shown in inspector if input field is empty?

  13. 13

    Why does the backing field of my property not change its value?

  14. 14

    In AngularJS, how does $scope get passed to scope?

  15. 15

    Why a changed to a $scope field is not propagated to another field?

  16. 16

    Why is my AngularJS $scope not working?

  17. 17

    Why AngularJS $scope is not working correctly?

  18. 18

    Does .bind break $scope in angularjs?

  19. 19

    How does Module change the scope?

  20. 20

    Why does Git ignore these folders?

  21. 21

    Why does FloatToStr ignore ThousandSeparator?

  22. 22

    Why does setInterval() ignore errors?

  23. 23

    Why does GLSL ignore return?

  24. 24

    Why does sudo ignore aliases?

  25. 25

    Why does bash ignore SIGTERM?

  26. 26

    Why Gulp does not ignore the file?

  27. 27

    AngularJS Populating input field with directive but not captured in $scope

  28. 28

    AngularJs: Why does scope inside my directive not update when async data arrives?

  29. 29

    angularJS: Why does binding to scope inside a directive result in lost content of ng-repeat?

HotTag

Archive