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