Angularjs:ng秀需要一些时间来反思
我有一个搜索页面,上面写着“search_page.html”。如果用户单击搜索按钮,但没有找到任何记录,我想显示用户的“没有找到记录”消息 以下是显示消息的代码:Angularjs:ng秀需要一些时间来反思,angularjs,Angularjs,我有一个搜索页面,上面写着“search_page.html”。如果用户单击搜索按钮,但没有找到任何记录,我想显示用户的“没有找到记录”消息 以下是显示消息的代码: <div nng-show="list.length==0"> <span>No record is found</span> </div> <div ng-repeat="x in list"> --showing th
<div nng-show="list.length==0">
<span>No record is found</span>
</div>
<div ng-repeat="x in list">
--showing the record here
</div>
没有找到任何记录
--在这里显示记录
当用户在文本框中键入内容并单击搜索按钮时
显示“未找到任何记录”,如果存在搜索记录,则在一段时间后它将消失,并显示记录
有人能给我推荐更好的解决方案吗?我只想在没有搜索结果的情况下显示消息 我想要这样的东西 所以基本上,使它工作的是
ng repeat
<li ng-repeat='item in vm.filtered = (vm.items | filter: vm.query)'>{{item}}</li>
未找到匹配项
因此,这可以使用一个复杂的代码来完成,例如:
在控制器中:
$scope.noRecords = false;
Service.getRecord(function(data){
$scope.list = data.list;
if($scope.list.length == 0){
$scope.noRecords = true;
}
});
在HTML中:
<div ng-show="noRecords">
<span>No record is found</span>
</div>
<div ng-repeat="x in list">
--showing the record here
</div>
没有找到任何记录
--在这里显示记录
这样它应该可以正常工作最后,我必须更改控制器和视图。 以下是我的解决方案: 视图中:
<div class="divEmpty" id="divNoRecord">
No record is found
</div>
.divEmpty {
display:none;
text-align:center;
}
控制器
if ($scope.list.length == 0) {
angular.element(document.getElementById('divNoRecord')).show();
}
else {
angular.element(document.getElementById('divNoRecord')).hide();
}
我也尝试过使用隐形斗篷,但不起作用。是的,这肯定会起作用。但我们可以不编写任何js代码就这样做吗?我只想在html文件中更改代码。因为我的项目是实时的,我不想更改控制器代码。使用有效的解决方案是不可能的。如果您可以更改控制器,那么您应该这样做。