Jam*_*mes 6 collections typescript ngfor angular
标题可能有误导性,我详细解释一下。
假设我们有一个集合并使用ngfor它在 html 中绑定它们。然后,对于每个集合,根据条件,我们将值传递给子组件。例如:
<ng-template ngFor let-person="$implicit" [ngForOf]="peopleAsPreviousCurrentAndNextTriplets" let-i=index let-last=last>
<app-card
[decrement]="(2 - i)"
[defaultDiff]="(+30) * (2 - i)"
[prevCard]="person.previous"
[currentCard]="person.current"
[nextCard]="person.next"
></app-card>
</ng-template>Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我们正在经过[prevCard], [currentCard],[nextCard]传递给集合中每个元素的组件。
然而我不想要这个。
我只想通过[prevCard],,[currentCard]当[nextCard]。last如果没有last那么我只想通过[currentCard]。
我怎样才能在这里做到这一点?
您可以使用三元运算符来检查当前是否位于最后一个元素:
[prevCard]="last === person ? person.previous : null"
Run Code Online (Sandbox Code Playgroud)
然后您可以对其他输入执行相同的操作。
| 归档时间: |
|
| 查看次数: |
5769 次 |
| 最近记录: |