ng-如果显示和隐藏TD数据



附加的是我的代码,在ng-if是true

的情况下尝试显示TD数据
 <tbody>
 <tr ng-repeat="fellow in fellowships">
   <td>{{$index}}</td>
   <td>{{fellow.Fellowship_Name}}</td>
   <div ng-repeat="value in data_report"
        ng-if="(fellow.F_Id==value.fellowship_id)? (show_row = true) : (show_row=false)">
     <td ng-show="show_row">{{value.Completed}}</td>
     <td ng-hide="show_row">0</td>
     <td ng-show="show_row">{{value.Not_Updated}}</td>
     <td ng-hide="show_row">0</td>
     <td ng-show="show_row">{{value.Total_schedule}}</td>
     <td ng-hide="show_row">0</td>
   </div>
 </tr>
 </tbody>

结果仅给0。尽管data_report有值尝试在TD中添加TD中的跨度,并导致跨度。结果仍然是零

我可以知道逻辑在哪里出错以及如何实现吗?

将代码更改为

   <tbody>
    <tr ng-repeat="fellow in fellowships">
    <td>{{$index}}</td>
    <td>{{fellow.Fellowship_Name}}</td>
    <td>
    <span ng-repeat="value in data_report" ng-show ="fellow.F_Id==value.fellowship_id">{{value.Completed}}</span>
    </td>
    <td>
    <span ng-repeat="value in data_report" ng-show="fellow.F_Id==value.fellowship_id">{{value.Not_Updated}}</span>
    </td>
    <td>
   <span ng-repeat="value in data_report" ng-show="fellow.F_Id==value.fellowship_id">{{value.Total_schedule}}</span>
    </td>
</tr>
</tbody>

在这里我得到的值,但是如果没有值,我如何将默认值设置为零?

在您的情况下, ng-if返回no boolean

用法是(文档):

<ANY
  ng-if="expression">
...
</ANY>

我认为您根本不需要ng-if。您可以写类似:

 <tbody>
 <tr ng-repeat="fellow in fellowships">
   <td>{{$index}}</td>
   <td>{{fellow.Fellowship_Name}}</td>
   <div ng-repeat="value in data_report">
     <td>{{(fellow.F_Id==value.fellowship_id) ? value.Completed: 0}}</td>
     <td>{{(fellow.F_Id==value.fellowship_id) ? value.Not_Updated: 0}}</td>
     <td>{{(fellow.F_Id==value.fellowship_id) ? value.Total_schedule: 0}}</td>
   </div>
 </tr>
 </tbody>

它不是最佳解决方案,在JavaScript中,您可以将value.Completed设置为默认情况下为0。它将帮助您简化HTML

最新更新