在ng build --prod am gettng错误,'对象'类型上不存在属性'email'

sus*_*ala 4 typescript ecmascript-6 angular2-forms angular ng-build

在login.component.ts中声明loginObj,如下所示

 public loginObj: Object = {
   email:'',
   password:''
 };
 public registerObj: Object = {
  email:'',
  name:'',
  password:''
 };
Run Code Online (Sandbox Code Playgroud)

HTML

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

Kra*_*ken 6

错误是正确的,此属性不存在.你需要创建界面

export interface LoginObject {
   email:string;
   password:string;
}
Run Code Online (Sandbox Code Playgroud)

adn然后将其导入您的组件并声明您的对象

public loginObj: LoginObject = {
   email:'',
   password:''
 };
Run Code Online (Sandbox Code Playgroud)

你甚至可以试着像这样声明它

public loginObj: LoginObject;
Run Code Online (Sandbox Code Playgroud)

它会对你有用


Wil*_*rth 5

将类型设为 any 而不是 Object 或定义一个接口并将其设为类型。