简体   繁体   中英

Conditional expression in Angular.js templates

I'm trying to build a monthly calendar using Angular.js, and I can't seem to find a way of outputting expressions when conditions are satisfied.

  <tr>
    <td ng-repeat="date in dates">
      {{date}}
    </td>
    {{'</tr><tr>' | if date.getDay() === 0}}
  </tr>

Or

  <tr>
    <td ng-repeat="date in dates">
      {{date}}
      {{ if date.getDay() === 0 expr = '</tr><tr>' else expr = ''}}
    </td>
    {{expr}}
  </tr>

How could I achieve this?

Thanks.

You could use the built in ng-if directive.

<tr ng-if="date.getDay() === 0">

The better solution could be a nested ng-repeat so you don't even have to do these checks. For instance:

<tr ng-repeat="week in weeks">
    <td ng-repeat="day in week.days">...</td>
</td>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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