0

I am trying to pass the alt text value on image and here's the code:

 <img *ngIf="document.story_image_1 " [src]="document.story_image_1 " class="image-1" alt="{{document.image_alttxt | 'default alt text'}}"  />

For the alt attribute, if the value is empty, I'd like it to have a default alt text. Please suggest what is the correct syntax to display data using if else statement.

1 Answer 1

1

You should use logical OR not bitwise OR

alt="{{document.image_alttxt || 'default alt text'}}"

you can also use optional chaining (?.) if document could be undefined

alt="{{document?.image_alttxt || 'default alt text'}}"
Sign up to request clarification or add additional context in comments.

Comments

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.