【问题标题】:Angular Bootstrap modal not updating tableAngular Bootstrap 模态不更新表
【发布时间】:2017-03-04 13:57:04
【问题描述】:

Angular Bootstrap modal 不更新表,如果 $scope.test() 从 ng-click 事件调用,它会刷新表,但从 $scope.closeAdjustmentModal(关闭模式的函数)它没有得到更新。

$scope.modalInstance = $uibModal.open({
                    animation : false,
                    scope : $scope,
                    size : 'lg',
                    controller : 'myCtrl',
                    templateUrl : '/showAdjustmentUI'

                   });

$scope.test= function() {
    $http.get('/myurl/getById/' + $scope.id).
    success(function(data) {
        $scope.patData = data;
    });
}

$scope.closeAdjustmentModal = function() {
    $scope.test();
    $scope.modalInstance.dismiss();
}

【问题讨论】:

    标签: angularjs angular-ui-bootstrap


    【解决方案1】:

    正如我在您的代码中看到的,您正试图从您的模态控制器调用您的主控制器方法test

    对于这种场景你可以使用closed.then回调来调用test函数。

    var modalInstance = $uibModal.open({
        animation : false,
                    scope : $scope,
                    size : 'lg',
                    controller : 'myCtrl',
                    templateUrl : '/showAdjustmentUI'
    }).closed.then(function(){
      $scope.test();
    });
    

    【讨论】:

    • 那么你不能用这个closed.then回调来调用你的test方法吗??
    • 两者都在同一个控制器“myCtrl”中。实际上, test() 也被调用,当调用 $scope.closeAdjustmentModal() 时,如果我在成功后发出警报,它会弹出但它无法将 $scope.patData 绑定到 UI
    • 那么这是你的数据绑定的问题。也可以使用 html 代码编辑您的答案
    • 但是如果直接从 ng-click 调用 test(),数据会显示在 UI 上。所以,我不认为这是 UI 的数据绑定问题。如果从模态调用,则不是绑定数据。
    • 你确定,当你关闭模式时,你得到了不同类型的数据值?
    猜你喜欢
    • 2014-01-02
    • 2016-02-17
    • 1970-01-01
    • 1970-01-01
    • 2016-03-04
    • 2015-11-22
    • 2023-03-24
    • 2018-11-26
    • 1970-01-01
    相关资源
    最近更新 更多