title: I'm having trouble with two way data binding in Angular 8
body: <p>So, I've worked extensively with AngularJS but I'm new to Angular 8.
  Now my problem is related to the two way data binding of Angular. I've already searched stackoverflow but couldn't find proper solution and that's why I'm posting this. My code contains an external data object as follows</p>
  
  <pre><code>export class Contact {
   name: string;
   email: string;
   phone: string;
   message: string;
  }
  </code></pre>
  
  <p>I've imported the above in my component where I've to use this class object. The relevant code from my component is:</p>
  
  <pre><code>import { Contact } from '../contactDetails';
  contact: Contact;
  processForm(){
  const allInfo=`My name is ${this.contact.name}. My email is ${this.contact.email}. My phone number is 
                 ${this.contact.phone}. My message is ${this.contact.message}`;
  alert(allInfo);
  }
  </code></pre>
  
  <p>The relevant code of the corresponding template is:</p>
  
  <pre><code>&lt;form class="contact-bg" id="contact-form" name="contact-form"&gt;
  
  &lt;input type="text" name="name" class="form-control" placeholder="Your Name*" 
   [ngModel]="contact?.name" (ngModel)="contact.name"/&gt;
  
  &lt;input type="email" name="email" class="form-control" placeholder="Your E-mail*" 
   [ngModel]="contact?.email" (ngModel)="contact.email"/&gt;
  
  &lt;input type="text" name="phone" class="form-control" placeholder="Phone Number" 
   [ngModel]="contact?.phone" (ngModel)="contact.phone"/&gt;
  
  &lt;textarea name="message" class="form-control" placeholder="Your Message*" style="height:120px"  
   [ngModel]="contact?.message" (ngModel)="contact.message"&gt;&lt;/textarea&gt;
  
  &lt;button (click)="processForm(contact)" id="submit" type="submit" name="submit"&gt;Send&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The problem I'm facing is when I try to submit my form after filling all details it gives me error:</p>
  
  <blockquote>
  <pre><code>ERROR TypeError: Cannot read property 'name' of undefined
  at ContactComponent.processForm (contact.component.ts:25)
  at Object.eval \[as handleEvent\] (ContactComponent.html:47)
  at handleEvent (core.js:38098)
  at callWithDebugContext (core.js:39716)
  at Object.debugHandleEvent \[as handleEvent\] (core.js:39352)
  at dispatchEvent (core.js:25818)
  at core.js:37030
  at HTMLButtonElement.&lt;anonymous&gt; (platform-browser.js:1789)
  at ZoneDelegate.invokeTask (zone-evergreen.js:391)
  at Object.onInvokeTask (core.js:34182)][1]][1]
  </code></pre>
  </blockquote>
  
  <p>Attached is the screenshot for the same.</p>
  
  <p>I'm sure that there's some syntactical error, but I'm not able to find one. Can someone please help me to find out the same? Thanks in advance.</p>
  
  <p>P.S.: I've only given the relevant code snippet from my component and template and not the complete code. Please assume that the boilerplate code is already there.</p>