2016-01-20 32 views
0

我在我的angular.js應用程序中使用了數據表。在此更新後,我需要顯示更新結果而不刷新整個頁面。只有表格必須刷新並更新爲新值。請幫忙。在angular.js中編輯後立即刷新數據表

這是我Controller.js

$scope.updateInternship = function() { 
    $("#internshipEdit").modal('hide'); 
    internshipService.updateInternship(
     $scope.internship, 
     function(data) { 
      $rootScope.loggedInUser = data; 
      $scope.internship = data; 
      $growl.box(
       'Hello!', 
       'Your details have been updated.', 
       { 
        class : 'success', 
        sticky : false, 
        timeout : 5000 
       } 
      ).open(); 
     } 
    ); 
} 

這是表格中顯示的HTML頁面。

<table datatable="ng" dt-options="dtOptions" cellspacing="0" width="100%" class="table table-striped table-hover table-bordered"> 
    <thead> 
     <tr> 
      <th>Id</th> 
      <th>Title</th> 
      <th>Category</th> 
      <th>Status</th> 
      <th>Created date</th> 
      <th>Action</th> 
     </tr> 
    </thead> 
    <tfoot> 
     <tr> 
      <th>Id</th> 
      <th>Title</th> 
      <th>Category</th> 
      <th>Status</th> 
      <th>Created date</th> 
      <th>Action</th> 
     </tr> 
    </tfoot> 
    <tbody> 
     <tr ng-repeat="internship in allinternships"> 
      <td><span>{{$index+1}}</span></td> 
      <td><span>{{internship.title}}</span></td> 
      <td><span>{{internship.category.name}}</span></td> 
      <td><span>{{internship.status}}</span></td> 
      <td><span>{{internship.appliedDate | date:'d MMMM yyyy'}}</span></td> 
      <td> 
       <button class="btn btn-default btn-sm" data-title="Hold" data-toggle="modal" ng-click="hold(internship.id)"> 
        <i class="fa fa-pause"></i> 
       </button> 
       <a href="javascript:;" class="btn btn-default btn-sm" data-title="Edit" data-toggle="modal" ng-click="update(internship.id)" > 
        <i class="icon bb-edit"></i> 
       </a> 
       <button class="btn btn-default btn-sm" data-title="View" data-toggle="modal" ng-click="deleteinternship(internship.id,$index)"> 
        <i class="icon bb-trash"></i> 
       </button> 
       <button class="btn btn-default btn-sm" data-title="View" data-toggle="modal" ng-click="viewInternship(internship.id)"> 
        <i class="icon bb-view"></i> 
       </button> 
      </td> 
     </tr> 
    </tbody> 
</table> 
+0

第一次加載控制器時,它是不是反映了表中的數據,還是在某處更改/更新數據,並且它在表中顯示? – Elfayer

+0

更改數據後,您可以嘗試調用'$ scope。$ apply();'。 – Elfayer

+0

改變數據後它不反映..需要刷新頁面纔有它的反映。 – Jayashree

回答

0

你可以試試這個解決方案:

  1. 如果使用路由提供商,您可以使用

    $ route.reload();

  2. 如果您正在使用$國家提供者,那麼你可以使用

    $ state.reload();

對不起,如果我誤解你的情況。

0

嘗試在更新數據後添加$scope.$apply();

否則嘗試:

$scope.$watch(function() { 
    // Here you should return the value that changes 
    return $scope.internship; 
}, function() { 
    // You arrive here if the returned element before has changed 
    $scope.internship = data; 
}); 

我有困難,瞭解你在做什麼的行爲。讓我知道它是否有幫助。