javascriptangularjsng-showng-hideangularjs-ng-if

AngularJS ng-hide/show label/button if length(description) < 20


I need to show/hide label if length(description) < one row. Code is working ok, but if length < one row, label isn't hide. How to hide/show label?

If [[ demandAd.description ]] less than one line or less than one row(or length < 100), I need to hide label because it doesn't have a function at that time

<div class="demand">
    <p class="demand-ad-time">[[demandAd.createdAt | date:"dd.MM.yyyy."]]</p>
    <input type="checkbox" class="read-more-state" id="demandAd[[ demandAd.id ]]" />
    <p>[[ demandAd.description ]]</p>
    <label for="demandAd[[ demandAd.id ]]" class="read-more-trigger"></label>
    <hr>
    <div class="demand-chips">
        <div class="demand-chip" ng-repeat="demandAdLabel in demandAd.labelsWithPlaces track by $index">[[ demandAdLabel ]]</div>
    </div>

Solution

  • Hope I understand correctly, you want to hide a label when the text length is shorter than 100. You can compare the text length within ng-hide

    <body ng-app="">
    
    Hide base on text length: <input type="text" ng-model="myVar">
    
    <div ng-hide="myVar.length >= 3">
    <label>Hide when length >= than 3</label>
    </div>
    
    </body>
    

    Here is a live sample code:

    https://plnkr.co/edit/vHVXyNCTzPiuVwq2fyOG?p=preview