简体   繁体   English

如何在angularjs中仅显示基于特定条件的选定div元素

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

So this is the snippet of my code, the aim here is to either hide or show the h4 element based on my condition. 因此,这是我的代码段,此处的目的是根据我的情况隐藏或显示h4元素。

 <h4 ng-hide="data_startupcosts.note == ' '">THE COST OF STARTING THIS VENTURE</h4>
 <div ng-repeat="data_startupcosts in data.startupcosts track by $index">
 {{data_startupcosts.note}}
 <ul ng-repeat="data_startupcosts_lists in data_startupcosts.list track by $index">
 <li>

I used ng-hide with an expression but no luck...... any suggestions????? 我用ng-hide表示表达式,但是没有运气……有什么建议吗?

You use the data_startupcosts outside your ng-repeat , so that variable won't exist in there. 您可以在ng-repeat之外使用data_startupcosts ,以便该变量在那里不存在。 Instead use it inside your ng-repeat scope: 而是在ng-repeat范围内使用它:

<div ng-repeat="data_startupcosts in data.startupcosts track by $index">
    <h4 ng-hide="data_startupcosts.note == ' '">THE COST OF STARTING THIS VENTURE</h4>
    {{ data_startupcosts.note }}
    <ul ng-repeat="data_startupcosts_lists in data_startupcosts.list track by $index">
        <li>..</li>
    </ul>
</div>

Or, if you really want it outside the div, use ng-repeat-start : 或者,如果您确实希望在div 之外使用它,请使用ng-repeat-start

<h4 ng-repeat-start="data_startupcosts in data.startupcosts track by $index" 
    ng-hide="data_startupcosts.note == ' '">THE COST OF STARTING THIS VENTURE</h4>
<div ng-repeat-end>
    {{ data_startupcosts.note }}
    <ul ng-repeat="data_startupcosts_lists in data_startupcosts.list track by $index">
        <li>..</li>
    </ul>
</div>

Also make sure your condition is correct, you are comparing with a single space, but maybe there isn't any space? 还要确保您的条件正确,您正在与一个空格进行比较,但是也许没有任何空格? ( data_startupcosts.note == '' ) data_startupcosts.note == ''

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

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