on ng build --prod am gettng error,Property 'email' does not exist on type 'Object

sushanth dornala picture sushanth dornala · Mar 20, 2018 · Viewed 8.7k times · Source

declared loginObj in login.component.ts as below

 public loginObj: Object = {
   email:'',
   password:''
 };
 public registerObj: Object = {
  email:'',
  name:'',
  password:''
 };

HTML

<input placeholder="" type="text"  [(ngModel)]="loginObj.email" autofocus="true" required>
<input placeholder="" type="text"  [(ngModel)]="loginObj.password" autofocus="true" required>

Answer

Kraken picture Kraken · Mar 20, 2018

The error is right this property is not existing. You need to create interface

export interface LoginObject {
   email:string;
   password:string;
}

adn then import it into your component and declare your object like this

public loginObj: LoginObject = {
   email:'',
   password:''
 };

You can even try to declare it just like this

public loginObj: LoginObject;

and it will work for you