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

标签 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>

最佳答案

错误是这个属性不存在。你需要创建接口(interface)

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

然后将其导入到您的组件中并像这样声明您的对象

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

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

public loginObj: LoginObject;

它会为你工作

关于angular - 在 ng build --prod am gettng 错误上,属性 'email' 在类型 'Object 上不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49384907/

相关文章:

angular - angular-cli 文档中的 tree shaking 和死代码消除

angular - 如何绑定(bind)到 Angular2 中 li 标签的 keydown 事件?

angular - 如何在 Angular2 中使用 Observable 通过 id 查找数组元素

javascript - array.push 是一种重新分配的形式吗?

arrays - 如何使用 webpack ProvidePlugin 填充 Array.prototype.find?

html - 悬停时更改 Angular Material 扩展标题的颜色

Angular 6 StaticInjectorError : No provider for Options

javascript - 在 typescript Jest 上下文中, Node 配置配置是 `undefined` 吗?

node.js - Nestjs 存储库模式配置挑战

javascript - 使用 React.js 实现 SlideToggle 功能