一尘不染

在ng-repeat内单击ng时显示隐藏的div

angularjs

我正在使用Angular.js应用程序,该应用程序通过医疗程序的json文件进行过滤。当使用ng-
click单击(在同一页面上)过程名称时,我想显示每个过程的详细信息。这是我到目前为止的内容,.procedure-details div设置为显示:无:

<ul class="procedures">
    <li ng-repeat="procedure in procedures | filter:query | orderBy:orderProp">
        <h4><a href="#" ng-click="?">{{procedure.definition}}</a></h4>
         <div class="procedure-details">
            <p>Number of patient discharges: {{procedure.discharges}}</p>
            <p>Average amount covered by Medicare: {{procedure.covered}}</p>
            <p>Average total payments: {{procedure.payments}}</p>
         </div>
    </li>
</ul>

我在角度上很新。有什么建议?


阅读 273

收藏
2020-07-04

共1个答案

一尘不染

删除display:none,然后ng-show改用:

<ul class="procedures">
    <li ng-repeat="procedure in procedures | filter:query | orderBy:orderProp">
        <h4><a href="#" ng-click="showDetails = ! showDetails">{{procedure.definition}}</a></h4>
         <div class="procedure-details" ng-show="showDetails">
            <p>Number of patient discharges: {{procedure.discharges}}</p>
            <p>Average amount covered by Medicare: {{procedure.covered}}</p>
            <p>Average total payments: {{procedure.payments}}</p>
         </div>
    </li>
</ul>

这是小提琴:http :
//jsfiddle.net/asmKj/


您还可以ng-class用于切换课程:

<div class="procedure-details" ng-class="{ 'hidden': ! showDetails }">

我更喜欢这种方式,因为它使您可以进行一些不错的转换:http :
//jsfiddle.net/asmKj/1/

2020-07-04