您的表格没有被隐藏,因为您可能没有在删除表格内容后将 hasdata 的值更改为 false。
尝试这个,
在 html 中,
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<script data-require="angular.js@1.0.7" data-semver="1.0.7" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="smart-table.js"></script>
<script src="script.js"></script>
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet">
</head>
<body ng-controller="mainCtrl">
<h1>{{greetings}} Plunker!</h1>
<div ng-show="hasdata">
<smart-table config="globalConfig" columns="columnsConfig" rows="items"></smart-table>
</div>
</body>
</html>
在 Js 文件中,
var app=angular.module('myApp',['smartTable.table']);
app.controller('mainCtrl',['$scope',function(scope){
scope.greetings='hello';
scope.hasdata=true;
scope.doDelete = function(index) {
// alert("index "+index);
scope.items.splice(index,1);
if(scope.items.length===0){
//alert("scope.items.length "+scope.items.length);
scope.hasdata=false;
}
}
scope.items=[
{name:'mahesh',lastName:'kumar'},
{name:'sachin',lastName:'ramesh'},
{name:'varun',lastName:'gupta'},
{name:'vijay',lastName:'kumar'},
{name:'prem',lastName:'raj'},
{name:'gandhi',lastName:'gandhi'},
{name:'sathish',lastName:'kumar'},
{name:'ram',lastName:'prasad'},
{name:'siva',lastName:'guru'},
{name:'dilli',lastName:'ganesh'}
];
scope.globalConfig={
isPaginationEnabled:false,
selectionMode:'single'
};
scope.columnsConfig=[
{label:'name',map:'name'},
{label:'last Name',map:'lastName'},
{label:'actions',cellTemplateUrl:'delete.html'}
];
}])
在 delete.html 中,
<button ng-click="$parent.$parent.$parent.$parent.doDelete(displayedCollection.indexOf(dataRow))"
class="btn btn-xs btn-primary">
Delete
</button>
看看plunker中的工作演示
希望这能解决你的问题:)