Is there such thing as optional input() condition when passing value to components?

Viewed 4003

The title may be misleading, let me elaborate.

Lets say we have a collection and using ngfor to bind them in html. And then for each collection, based on condition we pass a value to a child component. For example:

<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>

As you can see, we're passing [prevCard], [currentCard], [nextCard] to component on every element in the collection.

However I don't want this.

I only want to pass [prevCard], [currentCard], [nextCard] when on last. And if not last then I only want to pass [currentCard].

How can I do this here?

3 Answers
Related