2016-04-30 34 views
0

我有一個表100行,如果我進入一個新的排它增加了它,並在表的頂部顯示爲降序按日期濾波器階與AngularJs

<table class="table"> 
<tr ng-repeat=" item in itemlist | orderBy:createdat:true"> 
<td>//code goes here</td> 
<td><button ng-click="del(item)" class="fa fa-trash"></button></td> 
</tr> 
</table> 

我有一個所有CRUD操作刪除按鈕,但問題是,當我刪除任何特定的行時,它只刪除該特定行,但仍顯示該行存在於表中,直到頁面被刷新。因此,任何想法..這將是對我很大的幫助.... 下面是代碼....只是在JS文件中的代碼複製plunker

在HTML

<div ng-app> 
<div ng-controller="FooController"> 
<table> 


    <tr ng-repeat="item in items | orderBy:'num':true"> 
     <td>{{item.num}} :: {{item.desc}}</td> 
     <td><button class="fa fa-trash" ng-click="del($index)"> 
     delete 
     </button></td> 
    </tr> 
    </table> 
</div> 

function FooController($scope) { 
$scope.items = [ 
    {desc: 'a', num: 1}, 
    {desc: 'b', num: 2}, 
    {desc: 'c', num: 3}, 
]; 
$scope.del=function(idx){ 
     $scope.items.splice(idx,1) 
} 
} 
+0

你可以創建plunker嗎? –

+0

太寬泛。也許創建一個演示。 – dfsq

+0

因此,您的代碼中存在一個錯誤,並希望找到並修復該錯誤。我們怎麼能沒有看到你的代碼呢? –

回答

0

HTML部分

<table> 
    <tr ng-repeat="item in items | orderBy:'num':true"> 
    <td>{{item.num}} :: {{item.desc}}</td> 
    <td> 
    <button class="fa fa-trash" ng-click="del(item)"> 
     delete 
    </button></td> 
    </tr> 
    </table> 

JavaScript部分

$scope.items = [ 
{desc: 'a', num: 1}, 
{desc: 'b', num: 2}, 
{desc: 'c', num: 3}, 
]; 
$scope.del=function(idx){ 
    $scope.items.splice($scope.items.indexOf(idx),1) 
} 
+0

謝謝@S。 Divya,它爲我工作,刪除數組的臨時數據。但以同樣的方式,我希望它從數據庫中刪除。那不過是工廠罷了。所以我正在尋找。 – ANK