【发布时间】:2019-03-17 06:16:33
【问题描述】:
我对 Angular 很陌生。我定义了一个导出一些字段的模型。在我将所有用户对象写入我的 ts 文件之前。现在我创建模型后出现错误:
ERROR TypeError: Cannot read property 'name' of undefined
我该如何解决这个错误?
这些是我的代码。
user.model.ts
export class User {
name: string = '';
email: string = '';
password: any = '';
}
register.component.ts
import { User } from '../../models/user.model';
export class RegisterComponent implements OnInit {
public form: User;
}
register.html
<form #signupForm=ngForm (ngSubmit)="onSubmit()">
<input type="text" name="name" #name="ngModel" [(ngModel)]="form.name" class="form-control" id="inputname3" placeholder="Enter Name" required>
【问题讨论】:
-
你在哪里设置了
form对象