ngIf with as as syntax and && operator

Viewed 229

How can I combine the ngIf as syntax with a && operator? The following code results in an "Expected identifier or keyword" error

 <control-error *ngIf="(createUserError | async as userError) && submitted">
          {{userError}}
 </control-error>
1 Answers

as syntax is applied only to the whole *ngIf expression.

So, this is the valid syntax:

*ngIf="(createUserError | async) && submitted as userError"

which will either hide that block or render true.

But in order to make it right and logicaly correct you can change the order:

*ngIf="submitted && (createUserError | async) as userError"

which should result in the right value for userError variable.

Related