添加数据后如何自动刷新AngularUI网格

How to refresh automatically Angular UI Grid after adding data

我有 angular UI-Grid,我想在添加数据后重新加载它。请让我知道我需要添加什么?

HTML 文件

<form class="form-main">
  <label>Category Name</label>
  <input type="text" id="txtCategory" ng-model="md_catname" />
  <button id="btnAdd" type="submit" class ="button-internal" ng-click="Add()">Add</button>    
  <div class="gridBigStyle" ui-grid="gridCategory" ui-grid-edit ui-grid-pagination>            
</form>

控制器文件

var myApp = angular.module('appHome');
myApp.controller("ctrlCategory", ['$scope', 'MetadataOrgFactory', 'CommonFunctionFactory', function ($scope, MetadataOrgFactory, CommonFunctionFactory) {
    $scope.gridCategory = {
        data: 'categoryData',        
        columnDefs: [
            {
                field: 'CategoryName', displayName: 'Name',                
            },           
        ]
    }

    //This is to retrieve existing categories from Database
    MetadataOrgFactory.getApiCall('getallcatgories', function (dataSuccess) {
        $scope.categoryData = dataSuccess;
    }, function (dataError) {
    });

    //Common Function being called to Add Category Name
    $scope.Add = function () {
        var objCategory = {
            'CategoryName': $scope.md_catname,            
        };
        CommonFunctionFactory.AddMasterData(objCategory, function (dataSuccess) {
        }, function (dataError) {
        });
    }
}])

常用函数文件

var appService = angular.module('appHome');
appService.factory('CommonFunctionFactory', ['MetadataOrgFactory', function (MetadataOrgFactory) {
    var dataFactory = {};

    //Adding Master Data to DB
    dataFactory.AddMasterData = function (objData) {
        MetadataOrgFactory.postApiCall(serviceFunc, objMasterData, function (dataSuccess) {
            alert("The request has been completed succesfully");
        }, function (dataError) {
    });
    };
}])

我想了解要放置什么代码,以便 Angular UI 在数据库中添加数据后自动刷新网格。

获取更新数据的完整列表作为更新成功的return,并将数据馈送到网格中,即$scope.gridOptions.data = latestData;