繁体   English   中英

如何设置显示角度的时间?

[英]how can i set a time to show something with angular?

我有一个搜索字段,当我搜索到任何东西却没有找到任何东西时,我会向用户显示一条消息,但是当有内容要显示时,消息错误会出现3到4秒钟,然后此消息消失并且搜索结果出现...

我的html:

<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> 

这是该想法的一个小示例: http : //plnkr.co/edit/IYtSKMHco52rHGWTT55W?p=preview

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM