我在我的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>
第一次加載控制器時,它是不是反映了表中的數據,還是在某處更改/更新數據,並且它在表中顯示? – Elfayer
更改數據後,您可以嘗試調用'$ scope。$ apply();'。 – Elfayer
改變數據後它不反映..需要刷新頁面纔有它的反映。 – Jayashree