Html 我如何设置时间来显示有角度的内容?
我有一个搜索字段,当我搜索某个内容但未找到任何内容时,我会向用户显示一条消息,但当有内容要显示时,消息错误会出现3~4秒,在这段时间后,消息消失,搜索结果出现 我的html:Html 我如何设置时间来显示有角度的内容?,html,angularjs,Html,Angularjs,我有一个搜索字段,当我搜索某个内容但未找到任何内容时,我会向用户显示一条消息,但当有内容要显示时,消息错误会出现3~4秒,在这段时间后,消息消失,搜索结果出现 我的html: <div> <h2>Search page</h2> <div class="container clearfix" ng-controller="restaurantsDataCtrl" group-by="category"> <restauran
<div>
<h2>Search page</h2>
<div class="container clearfix" ng-controller="restaurantsDataCtrl" group-by="category">
<restaurants-gallery ng-show="restaurants.length" category="{{list.category}}" restaurants="{{list.restaurants}}" ng-repeat="list in restaurantsByCategory">
</restaurants-gallery>
<p ng-show="!restaurants.length">Message nothing found.</p>
</div>
</div>
搜索页面
消息未找到任何内容
我需要的是设置此消息的显示时间,当此时间结束时,我将知道是否显示此消息。您可以做的一件事是创建一个标志来指示您的数据请求是否已开始:
$scope.completed = false
然后在数据请求的回调中,将该标志设置为true:
...
$http.get(...).then(function(response) {
$scope.completed = true;
$scope.restaurants = response.data;
}
如果您将其与您的条件相结合,以查看是否实际上没有餐厅,则可以保证只有在您尝试获取数据且未返回任何信息后,消息才会显示:
<p ng-show="!restaurants.length && completed">Message nothing found.</p>
消息未找到任何内容。
下面是这个想法的一个小例子:使用
$timeout
。与setTimeout
等效的内置服务。它看起来像是任何触发错误消息显示的东西都不应该触发它。错误消息显示应设置为对未检索到任何结果的成功调用的回调。您可以发布控制器代码吗?显示任务的典型方法是使用微调器,该微调器将向用户指示发生了什么。如果你没有提供一些迹象表明某个过程正在进行,他们可以离开。