繁体   English   中英

如果输入字段为空,则隐藏带有角度的div

[英]Hide a div with angular if the input field is empty

目前,如果视图加载并且输入字段没有焦点,我的代码将起作用。 div被以下代码隐藏:

<i class="icon ion-search placeholder-icon"></i>
      <input type="text" placeholder="Solothurn durchsuchen..." name="text" ng-model="searchBox.storeName">
    </label>
    <br><br>
    <div ng-repeat="item in posts | filter:searchBox" class="card has-header" ng-show="searchBox">
      <div class="w shop">{{item.storeName}}</div>
      <p class="w">

但是我的目标是,当用户删除输入字段中的文本时,div再次被隐藏。 我怎样才能做到这一点? 任何帮助,不胜感激!

只需使用ng-show="searchBox.storeName.length > 0"即可达到目的

<div ng-repeat="item in posts | filter:searchBox" class="card has-header" ng-if="searchBox.storeName != null">

要么

<div ng-repeat="item in posts | filter:searchBox" class="card has-header" ng-if="searchBox.storeName">

尝试这个

 <i class="icon ion-search placeholder-icon"></i>
          <input type="text" placeholder="Solothurn durchsuchen..." name="text" ng-model="searchBox.storeName">
        </label>
        <br><br>
        <div ng-repeat="item in posts | filter:searchBox" class="card has-header" ng-show="searchBox.storeName">
          <div class="w shop">{{item.storeName}}</div>
          <p class="w">

暂无
暂无

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

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