从模态修改时,角度ng网格不会刷新

时间:2015-06-22 21:57:06

标签: angularjs

在页面上,我有一些文本框和一个提交按钮。基于文本框和按钮单击的值,将显示网格。网格有一些列,后跟一个包含删除按钮的列。单击“删除”按钮可打开一个模式进行确认。在模态上单击是删除记录并关闭模态。理想情况下,网格应刷新并自动显示刷新的网格。但是,它没有。因此,我必须手动单击“提交”按钮以获取刷新的网格。这里有什么缓存吗?如何在不单击提交的情况下获取刷新的网格?

为简单起见,我只显示重要的代码

$scope.showGrid = function () { // Called on submit button click

        $http.post(postUrl, { type: $scope.selectedType, branchId: $scope.selectedBranch }).success(function (responseData) {

                $scope.gridData = JSON.parse(responseData.d);
        })
    };


// Function to delete a record
    $scope.deleteRecord = function (id) { // takes id of the record to delete

        var modalInstance = $modal.open({
            templateUrl: 'myModalContent.html',
            controller: 'ModalInstanceCtrl',
            resolve: {
                editId: function () {
                    return id;
                },
                type: function () {
                    return $scope.selectedType;
                }
            }
        });

        modalInstance.result.then(function () {
            $scope.gridData = '';  // I am clearing the variable just to ensure gridData doesnt have old values
            $scope.showGrid();  // calling the grid function
            toaster.success({ title: "Success", body: "The schedule has been deleted successfully!" });
        });
    };


app.controller('ModalInstanceCtrl', .... // Modal code to delete the record

1 个答案:

答案 0 :(得分:0)

您可以尝试从showGrid函数返回promise并在解析后调用烤面包机以防它们在某种程度上相互冲突

$scope.showGrid = function () { // Called on submit button click
    return $http.post(postUrl, { type: $scope.selectedType, branchId: $scope.selectedBranch }).success(function (responseData) {
        $scope.gridData = JSON.parse(responseData.d);
    })
};

// Function to delete a record
    $scope.deleteRecord = function (id) { // takes id of the record to delete

        var modalInstance = $modal.open({
            templateUrl: 'myModalContent.html',
            controller: 'ModalInstanceCtrl',
            resolve: {
                editId: function () {
                    return id;
                },
                type: function () {
                    return $scope.selectedType;
                }
            }
        });

        modalInstance.result.then(function () {
            $scope.gridData = '';  // I am clearing the variable just to ensure gridData doesnt have old values
            $scope.showGrid().then(function(){ // calling the grid function
                toaster.success({ title: "Success", body: "The schedule has been deleted successfully!" });
            });  

        });
    };