I have a requirement, I need to bind phone number to ngModel only if it's present. My code is as follows:
<cd-input
  size="15"
  [(ngModel)]="phone_numbers[0].full_number"
  [reformat]="something"
  [format]="something"
  placeholder="(111) 222-3333">
</cd-input>
This works well if phone number is present, but if it's not I get the following error:
Cannot read property 'full_number' of undefined
So based on this SO post LINK, I tried the following:
<cd-input
  size="15"
  [(ngModel)]="phone_numbers[0].length > 0 ? phone_numbers[0].full_number : null"
  [reformat]="something"
  [format]="something"
  placeholder="(111) 222-3333">
</cd-input>
But, this causes syntax error.
Uncaught Error: Template parse errors
One way to fix this is using *ngIf and repeating the set of code again. But, What should I do to do it inline, like a ternary condition check?
 
     
    