【发布时间】:2019-01-16 17:00:58
【问题描述】:
在 html 文件中,使用 ngModel,我想获取它的值以在我的组件中使用
edit-customer.component.html
<input id="userInfoEmail" type="text" class="form-control" value="{{userInfo.email}}" [(ngModel)]="userInfo.email" disabled>
由于它的双向绑定,我在我的组件中使用它如下,
edit-customer.component.ts
checkUserEmail(): void {
this.userInfo.email = this.userEmail;
this.customerService.checkEmail(this.userEmail).subscribe((res) => {
if (res.twoFactorEnabled === true) {
this.isButtonDisabled = false;
}
else {
this.isButtonDisabled = true;
}
})
}
我也声明了this.userEmail:string;,但不幸的是在我的控制台上出现错误“未定义”,我读到我需要初始化对象但无法弄清楚,
【问题讨论】:
-
如果你有
[(ngModel)],你就不需要value="{{userInfo.email}}",另外,你在组件中声明了userInfo:string = "";吗?
标签: angular typescript angular6 primeng angular-ngmodel