简体   繁体   English

如何使用ng-hide仅显示基于angularjs中特定条件的选定div元素

[英]How Can I show only selected div elements based on a certain condition in angularjs using ng-hide

The aim here is to either show or hide the below div element based on my preference 目的是根据我的喜好显示或隐藏下面的div元素

<div ng-repeat="data_training in data.training track by $index">
                                        <h4 ng-hide="data_training.list == [] && data_training.note == '' ">WHAT TYPE OF TRAINING IS REQUIRED TO START THIS VENTURE</h4> 
                                        {{data_training.note}}
                                            <ul ng-repeat="data_training_lists in data_training.list track by $index ">
                                                <li>
                                                    {{data_training_lists}}
                                                </li>
                                            </ul>
                                    </div>

This is just a snippet of my index.html and below is a snippet of my json data 这只是我的index.html的一个片段,下面是我的json数据的一个片段

 "training": [
      {
        "note": "",
        "list": [
          "Agricultural extension officers ",
          "Agricultural shops ",
          "Non Government Organisations, Community Based Organisations ",
          "Other farmers "
        ]
      }
    ],

wanted to display the h4 element if and if only either training.note or training.list have value on them. 如果且仅当training.note或training.list具有价值时,希望显示h4元素。 THANKS IN ADVANCE 提前致谢

只需检查长度是否> 0:

<h4 ng-hide="data_training.list.length && data_training.note.length">WHAT TYPE OF TRAINING IS REQUIRED TO START THIS VENTURE</h4>

Try this 尝试这个

<h4 ng-if="data_training.list.length && data_training.note.length">WHAT TYPE OF TRAINING IS REQUIRED TO START THIS VENTURE</h4>

Or with ng-show 或与ng-show

<h4 ng-show="data_training.list.length && data_training.note.length">WHAT TYPE OF TRAINING IS REQUIRED TO START THIS VENTURE</h4>

Or with ng-hide 或搭配ng-hide

<h4 ng-hide="data_training.list.length && data_training.note.length">WHAT TYPE OF TRAINING IS REQUIRED TO START THIS VENTURE</h4>

I prefer using ng-if over ng-show 我更喜欢使用ng-if不是ng-show

The ng-if directive removes the content from the page and ng-show/ng-hide uses the CSS display property to hide content. ng-if指令从页面中删除内容,而ng-show / ng-hide使用CSS display属性隐藏内容。

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

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