【发布时间】:2017-10-12 18:13:36
【问题描述】:
我在 ng:...template.html 中遇到错误 ERROR: Property 'email' does not exist on type '{}' whencompile using Angular Cli > ng build --prod --aot
表单模板:
<form (ngSubmit)="login()" #loginForm="ngForm">
<input [(ngModel)]="user.email" id="email"
type="email" class="validate" name="email" required>
<label for="email">Email</label>
...
</form>
登录组件:
export class LoginComponent {
public user = {};
public errorMsg = '';
email: any;
password: any;
constructor(
...
) {
在表单组件中添加类型 email:string 或 email:any 并不能解决问题。它似乎指的是工厂 Angular 组件 {}。我怎样才能绕过这个错误?
【问题讨论】:
-
你的组件的代码在哪里?你读过代码吗?您正在使用的
email字段位于组件的user字段上。不在组件上。 -
值在哪里以及如何分配给
user? -
我想这应该对用户有所帮助:any = {}
标签: angular