Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional expression requires all 3 expressions at the end

<div *ngFor="let f of layout?.photoframes; let i = index" [attr.data-index]="i">
   <input type="number" [(ngModel)]="f.x" [style.border-color]="(selectedObject===f) ? 'red'"  />
</div>

the conditional style throws the error

Conditional expression (selectedObject===f) ? 'red' requires all 3 expressions at the end
of the expression [(selectedObject===f) ? 'red'] what can I do?
like image 671
daniel Avatar asked Nov 30 '17 10:11

daniel


People also ask

What are conditional expressions?

A conditional expression if el then e2 else e3 fi evaluates to the current value of the expression e2 if the current (Boolean) value of the expression el is true, and the current value of the expression e3 otherwise.


2 Answers

You need also to pass the result of the case in which condition will return false. In other words you need to pass correct ternary operator

Something like if/else. If true return red, else return blue.

(selectedObject === f) ? 'red' : 'blue'
like image 152
Suren Srapyan Avatar answered Oct 17 '22 12:10

Suren Srapyan


This applies to a different context, but if you are using a pipe ( | ) in Angular and you get this error from your view you may need to put parentheses around your pipe like this:

<input value={{device.id ? (device.id | decimalToHex) : ''}}>

if you leave them off like this:

<input value={{device.id ? device.id | decimalToHex : ''}}>

Then you get this error

like image 13
BHinkson Avatar answered Oct 17 '22 12:10

BHinkson