title: angular 2 4 5 - how to define object variable in component.ts
body: <p>I want to define object variable in component.ts </p>
  
  <blockquote>
    <p>components.ts </p>
  </blockquote>
  
  <pre><code>  user: {
           brand: {
                   id: string,
                  name: string
           },
    [k: string]: any} = {};
  
    ==&gt; I want Define 'brand' object to the 'user' variable
  </code></pre>
  
  <blockquote>
    <p>view.html</p>
  </blockquote>
  
  <pre><code>  &lt;form class="example-form"&gt;
      &lt;mat-form-field class="example-full-width"&gt;
        &lt;input matInput [(ngModel)]="user.userName"&gt; ==&gt; *** No Error ***
      &lt;/mat-form-field&gt;
    &lt;/form&gt;
  
    &lt;form class="example-form"&gt;
      &lt;mat-form-field class="example-full-width"&gt;
        &lt;input matInput [(ngModel)]="user.brand.id"&gt; ==&gt; *** Error ***
      &lt;/mat-form-field&gt;
    &lt;/form&gt;
  </code></pre>
  
  <blockquote>
    <p>user.brand.id Error Message ==> Cannot read property 'id' of undefined</p>
  </blockquote>
  
  <p>Where the error is pointing  => user.brand.id </p>