Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么AngularJS忽略$scope字段更改?_Javascript_Angularjs_Stripe Payments - Fatal编程技术网

Javascript 为什么AngularJS忽略$scope字段更改?

Javascript 为什么AngularJS忽略$scope字段更改?,javascript,angularjs,stripe-payments,Javascript,Angularjs,Stripe Payments,我希望我的模态对话框在其上方的“条带检出”处于打开状态时变模糊,但由于某些原因,即使在我关闭了第二模态之后,它仍保持模糊 最好在样本中尝试 使用卡“4242”进行测试,包括任何未来的到期日期和CCV。模糊必须在条纹窗口关闭后消失,但由于某些原因它不会消失 这是所有基本的东西,我已经使用angular至少3年了,只是这次不知道bug在哪里 下面是上述示例中的JS代码: angular.module('ui.bootstrap.demo', ['ui.bootstrap']); angular.mo

我希望我的模态对话框在其上方的“条带检出”处于打开状态时变模糊,但由于某些原因,即使在我关闭了第二模态之后,它仍保持模糊

最好在样本中尝试

使用卡“4242”进行测试,包括任何未来的到期日期和CCV。模糊必须在条纹窗口关闭后消失,但由于某些原因它不会消失

这是所有基本的东西,我已经使用angular至少3年了,只是这次不知道bug在哪里

下面是上述示例中的JS代码:

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: 'foo@mail.com',
      });

  };

});

我假设
$scope.isbusy
没有按预期更改?条带回调不会通知:

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无法知道
$scope
变量已更改(除非
StripeCheckout
已经是角度服务)


理解angular的
$digest
处理信息的方式非常重要。简单地说,每当调用异步非角度服务的回调时,[回调必须使用
$scope.apply][1],如果它更改了
$scope`变量的状态。

是的,就是这样-$apply,我很不好意思承认我犯了这个基本错误:)不用担心,我根本不会称它为“基本”。此外,我想我们所有人都经常忘记一些基本的东西。我记得调试一个数据库连接几个小时-运行数据库会有帮助。。。