3

I'm trying to do a weird thing I guess since angular is complaining. Has anyone tried to mix interpolation and ternary in html code on Angular 4

On an input I'm trying to inject a matToolTip using ternary while using pipe to translate the string to show, like so:

<input
                typeaheadOptionField="name"
                typeaheadOptionsLimit="15"
                placeholder="{{ 'odal.selectPlaceholder' | translate }}"
                class="form-font-size form-control"
                style="vertical-align: middle"
                type='text'
                [matTooltip]="!isRefAutorized ? {{ 'modal.refSelect' | translate }} : null"
                (keyup.enter)="createStyle(styleCode.value)"
                #styleCode
            />

But angular complaining with

Parser Error: Got interpolation ({{}}) where expression was expected at column 18 in [!isRefAutorized ? {{ 'modal.selectPlaceholder' | translate }} : null]

it works fine when I do just:

 [matTooltip]="!isRefAutorized ? 'not authorized' : null"
2
  • Interpolation is required for non-angular html attributes to evaluate the expression. Can you try without the interpolation. Commented Dec 18, 2017 at 15:01
  • @RRForUI I tried but then I've got a different error since it does not evaluate the translate and consider it part of the ternary Commented Dec 18, 2017 at 15:06

1 Answer 1

6

You cannot do that.

Instead, you should change your code as following

[matTooltip]="!isRefAutorized ? ( 'modal.refSelect' | translate ) : null"

Sign up to request clarification or add additional context in comments.

1 Comment

marche nickel, merci

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.