angularjs - bootbox 回调问题

angularjs - bootbox callback issue

我有一个带有两个选项卡的视图,在第一个选项卡中我有文本输入 commentaireLien。

在控制器中,当我输入bootbox确认回调时,输入的commentaireLiens在浏览器中没有刷新("test")。
如果我进入视图中的另一个选项卡,然后返回包含 commentaireLiens 的选项卡,则会刷新它。

我不明白为什么。

bootbox.confirm({
    size: "small",
    message: "Voulez-vous valider le CV ?",
    callback: function (result) {
        if (result) {
            vm.commentaireLiens ="test";
        } 
    }
})
<input type="text" class="form-control" name="commentaireLiens"
       id="field_commentaireLiens"
       ng-model="vm.commentaireLiens"
/>
bootbox.confirm({
    size: "small",
    message: "Voulez-vous valider le CV ?",
    callback: function (result) {
        if (result) {
            vm.commentaireLiens ="test";
            $scope.$apply();
        } 
    }
})

AngularJS 通过提供自己的事件处理循环来修改正常的 JavaScript 流程。这将 JavaScript 分为经典和 AngularJS 执行上下文。只有在 AngularJS 执行上下文中应用的操作才会受益于 AngularJS data-binding、异常处理、属性 监视等......您还可以使用 $apply() 从 JavaScript.

进入 AngularJS 执行上下文

请记住,在大多数地方(控制器、服务)$apply 已经被处理事件的指令调用。仅当 实施自定义事件回调,或使用third-party 库回调 时,才需要显式调用$apply

有关详细信息,请参阅