Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 640
sushanth dornala Avatar asked Mar 20 '18 13:03

sushanth dornala


People also ask

How to solve Property does not exist on type?

The "Property does not exist on type '{}'" error occurs when we try to access or set a property that is not contained in the object's type. To solve the error, type the object properties explicitly or use a type with variable key names. Copied!

Does not exist on type error?

Conclusion # The error "Property 'status' does not exist on type 'Error'" occurs because the status property is not available on the Error interface. To solve the error, add the specific property to the Error interface or create a custom class that extends from Error .


2 Answers

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

like image 75
Kraken Avatar answered Nov 15 '22 07:11

Kraken


Make the type any instead of Object or define an interface and make it the type.

like image 21
William Allworth Avatar answered Nov 15 '22 07:11

William Allworth