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

时间:2018-03-20 13:00:38

标签: angular typescript ecmascript-6 angular2-forms ng-build

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

 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>

4 个答案:

答案 0 :(得分:5)

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

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

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

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

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

public loginObj: LoginObject;

它会对你有用

答案 1 :(得分:2)

使类型为any而不是Object或定义接口并使其成为类型。

答案 2 :(得分:1)

在jenkins中构建它时遇到类似的错误。以下命令解决了该问题:

npm install
npm run ng build --prod

希望有帮助

答案 3 :(得分:0)

尝试在 package.json 中添加此依赖项 "@angular/compiler-cli":"9.0.0(或您使用的其他版本)"

相关问题