Angular UI Datepicker 没有在 Dates-Disabled 函数中接收更新的范围变量

Angular UI Datepicker Isn't Receiving Updated Scope Variable In Dates-Disabled Function

我正在使用 AngularJS 和 Angular UI Bootstrap。

我 运行 遇到了一个问题,起初我认为是范围问题,然后是初始化问题,现在我不知道问题是什么。我在这里发布一个 plunker,希望有人能帮助我解决我的问题。

用户案例如下:某人select想买一个甜甜圈。如果那个甜甜圈不是每天都烤,然后模式弹出并提示他们 select 订购日期。我的问题是日期选择器似乎不知道 $scope.theActiveDonut 是什么,它只是恢复到初始化时的默认值,奶油甜甜圈,即使我的控制台日志和 angular.element([=13=]).scope() 告诉我 $scope.theActiveDonut 已经改变。您可以在 console.log().

中看到这一点

我的笨蛋来了:http://plnkr.co/edit/rziyPLvsiiZB346qmSC5?p=preview

如您所见,console.log() 反映了 $scope.theActiveDonut 已更改,但从 $scope.thingy 内部来看,$scope.theActiveDonut 始终是奶油甜甜圈。

模态实例不共享父控制器的范围。他们有自己的范围。

为了将变量从调用控制器传递到模态实例,使用解析:

modalInstance = $modal.open({
          animation: false,
          templateUrl: 'myModalContent.html',
          controller: 'MainController',
          scope: $scope,
          size: "lg",
          resolve: {
            theActiveDonut: function() { return $scope.theActiveDonut }
          }
        });

您需要为 $modal 创建一个单独的控制器并使用

将数据发送到该控制器
resolve: {
            theActiveDonut: function() { return $scope.theActiveDonut }
          }

初始化模态时。然后从模式中,一旦选择了日期并且用户单击 'Okay',您应该 modalInstanceII.close('making-a-new-one'); 或者如果他们单击取消 modalInstanceII.dismiss('canceled');

笨蛋:http://plnkr.co/edit/mUIfZOEqj3r0zNw5rQDB?p=preview