Angular:在没有导致角度重复的情况下显示消息? (具体情况)

时间:2015-01-20 17:29:12

标签: javascript angularjs

我有一个特定的情况,我在手风琴中重复我的数据,我需要的是当过滤器(搜索框)在ng-repeat="sport in sports"上没有返回任何内容时向用户显示一条消息

<input ng-model="query" placeholder="Search sports...">
   <accordion close-others="false">
       <accordion-group ng-repeat="sport in sports | filter:query"
                        ng-show="sport.leagues.length">
         <accordion-heading>
           <div ng-click="addSportToLines(sport);">
              {{::sport.name}}
           </div>
          </accordion-heading>
          <div class="list-group leagues-margin">
           <a href="javascript:void(0);" class="list-group-item"
              ng-repeat="league in sport.leagues"
              ng-class="{active: league.active}"
              ng-click="addLeagueToLines(league)">{{::league.name}}
           </a>
         </div>
       </accordion-group>
     </accordion>

1 个答案:

答案 0 :(得分:2)

试试这个,

<div ng-show="!(sports | filter:query).length">No items</div>

或者,我们可以通过将过滤结果分配给另一个变量(如下所示)来消除一个过滤器,

<accordion close-others="false">
       <accordion-group ng-repeat="sport in filteredSports = (sports | filter: query)"
                        ng-show="sport.leagues.length">
         <accordion-heading>
           ...
       </accordion-group>
     </accordion>

<div ng-show="!filteredSports.length">No items</div>

感谢。