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


the title may misleading, let me elaborate.

lets have collection , using ngfor bind them in html. , each collection, based on condition pass value child component. 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 can see, we're passing [prevcard], [currentcard], [nextcard] component on every element in collection.

however don't want this.

i want pass [prevcard], [currentcard], [nextcard] when on last. , if not last want pass [currentcard].

how can here?

you use ternary operator check if on last element:

[prevcard]="last === person ? person.previous : null"  

then same other inputs.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -