【问题标题】:How to reload the view page after updating the data in database in angular如何在角度更新数据库中的数据后重新加载视图页面
【发布时间】:2016-07-11 14:00:53
【问题描述】:

我是 Angular 的新手。请帮我解决这个问题。我有 display.html,其中显示了记录列表,并有一个复选框来选择和更新数据库中的选定记录。一旦记录在数据库中更新,我需要用数据库中新更新的记录刷新 Display.html

**Display.html:**

     <div data-ng-controller="SKUIntegrationCtrl">

    <table class="table table-striped table-hover" width="100%"
        style="overflow-x: scroll;">
        <tr>
            <th><input type="checkbox" ng-model="selectedAll"
                ng-click="checkAll()" /></th>
            <th class="imagetableth"><b>UniqueID</b></th>
            <th class="imagetableth"><b>Style</b></th>
        </tr>
        <tr
            ng-repeat="datalist in datalists| pagination: curPage * pageSize | limitTo: pageSize">
            <td><input type="checkbox" ng-model="datalist.selected"
                value="datalist.uniqueid"> </input></td>
            <td class="val"><span class="glyphicon sort-icon">                {{datalist.uniqueid}}
            </span></td>
            <td class="val"><span class="glyphicon sort-icon">{{datalist.style}}
            </span></td>
        </tr>
    </table>
    <input type="button" name="Search" value=""
        ng-disabled="authenticatedUser" ng-click="updateDataExtractionSAP()"
        ng-class="enableDisableButton" />
       </div>

**DisplayCtrl.js**

   $scope.updateDataExtractionSAP = function (docName,ida3a11) {
        SKUIntegrationService.updateDataExtractionSAP($scope, $http);
        $route.reload();
        alert("Reload");
    };

**DisplayService.js**

       this.updateDataExtractionSAP = function ($scope, $http) {
        var SkuIntegrationSearchVo = {};

              $scope.uniqueIDArray = [];
              angular.forEach($scope.datalists, function(datalist){
                if (!!datalist.selected){
                    $scope.uniqueIDArray.push(datalist.uniqueid);
                }
              })

        SkuIntegrationSearchVo.uniqueIDList =  $scope.uniqueIDArray;
        var scopevalue = document.getElementById("contentlayout");
        var controllerScope = angular.element(scopevalue).scope();
        controllerScope.documentcriteriadata = SkuIntegrationSearchVo;


        $scope.toggleloading();
        var promise =    $http.post('/PMDBViewer/userlogin/LandingLayout/updateDataExtractionSAPList',    SkuIntegrationSearchVo);
        promise.success(function (data, status, headers, config) {
            $scope.toggleloading();
            var scopevalue = document.getElementById("contentlayout");
            var controllerScope = angular.element(scopevalue).scope();
            controllerScope.datalists = data;
            controllerScope.content = "SkuIntegrationSearchResult";
            $scope.showAdvPrdSearch = false;
            $scope.showsearchresult = true;
            alert("Selected records updated in DataExtractionToSAP table");
        }).error(function (data, status, headers, config) {
            $scope.toggleloading();
            alert("error in advance Document Search");
        });
    };


Now i have an action method to update the records selected in check box in display.html to the database. It is working fine. Now i need to re-load the display.html with the newly update values in database. Please help me on this. i tried 

    $route.reload();

it seems not working

【问题讨论】:

  • 你不能再次检索数据列表吗?
  • 请帮我写代码 sn-p。
  • 可能首先显示完整的 DisplayCtrl.js

标签: angularjs reload


【解决方案1】:

您可以通过添加您的函数调用来做到这一点,该调用正在获取要在另一个函数中显示的数据。 function getData(){...} function activate(){getData()}add activate() 在您的控制器中。所以每次你在最后添加更新数据时再次调用激活函数。

【讨论】:

    猜你喜欢
    • 2019-12-11
    • 2020-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-07
    相关资源
    最近更新 更多