这是我的代码。如果loadTags返回空结果,那么有什么方法可以显示未找到结果的消息吗?
<tags-input ng-model="tags" on-invalid-tag='test'
display-property="Name" add-from-autocomplete-only="true"
tabindex="3">
<auto-complete source="loadTags($query)"></auto-complete>
</tags-input>
我不知道你使用的是什么api/data(Array)我们必须在ng中使用ng show repeat来显示html中的show"No result found"标签这里是代码
function MyCtrl($scope, $filter)
{ $scope.nodata = false;
$scope.items = [
{id:1, name:'John'},
{id:2, name:'Steve'},
{id:3, name:'Joey'},
{id:4, name:'Mary'},
{id:5, name:'Marylin'}];
$scope.items2 = $scope.items;
$scope.$watch('search', function(val)
{
console.log($filter('filter')($scope.items2, val));
$scope.items = $filter('filter')($scope.items2, val); // items return for api after search if array is empty
if($filter('filter')($scope.items2, val).length == 0){ // item are empty
$scope.nodata = true;
}
else{
$scope.nodata = false;
}
});
};
HTML
<div ng-app>
<div ng-controller="MyCtrl">
<input type="text" ng-model="search">
<table>
<tbody>
<div ng-show="nodata">NO results found</div>
<tr ng-repeat="item in items">
<td>{{item.id}}</td>
<td>{{item.name}}</td>
</tr>
</tbody>
</table>
</div>
</div>
CSS代码
.no_rocord{border-color: #ececec;
border-width: 1px;
border-style: solid;
border-radius: 2px;
width: 250px;
padding: 6px;
cursor: pointer;
z-index: 9999;
position: absolute;
margin-top: -6px;
background-color: #ffffff
}
JS FIDDLE