[英]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.