0

I am now using the ? operator to check if an object exists when interpolating the values in my html. For example:

<input type="text" class="" name="iptname" value="{{object?.property}}" #iptname>

This works. But how to check ? with an array. The below code throughs me an error saying array is undefined.

<input type="text" class="" name="iptname" value="{{object?.array[arrayindex].property}}" #iptname>  

My Failed Attempt

<input type="text" class="" name="iptname" value="{{object?.array?[arrayindex].property}}" #iptname>  

But this does not work. So how can I interpolate through arrays keeping the array variable optional?

1
  • 1
    Stackblitz repro would be helpful :) Commented May 24, 2018 at 10:26

1 Answer 1

2

Try this

<input type="text" class="" name="iptname" [attr.value]="object?.array[arrayindex]?.property" #iptname> 
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.