如何解决找不到名称的控件:<文本输入控件名称>
我是 Angular 开发的新手,正在尝试创建一个包含 3 个文本用户输入的简单表单。
Error: Cannot find control with name: 'teamId'
at _throwError (sources:///node_modules/@angular/forms/fesm2015/forms.js:2912:9)
HTML 代码:
<form [formGroup]="profileForm">
<label>
Tab name:
<input type="text" formControlName="tabName">
</label>
<label>
Team Id:
<input type="text" formControlName="teamId">
</label>
<label>
Channel Id:
<input type="text" formControlName="channelId">
</label>
TS 代码:
import { AfterViewInit,ChangeDetectorRef,Component } from '@angular/core';
import { FormControl,FormGroup } from '@angular/forms';
import { MatDialogRef } from '@angular/material/dialog';
export class MyComponent implements AfterViewInit{
public profileForm: FormGroup;
constructor(
private readonly dialogRef: MatDialogRef<MyComponent>,private readonly changeDetector: ChangeDetectorRef,) {
this.profileForm = new FormGroup({
tabName: new FormControl(''),teamdId: new FormControl(''),channelId: new FormControl(''),});
}
ngAfterViewInit(): void {
this.changeDetector.markForCheck();
}
public close() {
this.dialogRef.close();
}
我正在我的模块定义中导入 FormsModule,ReactiveFormsModule
。
奇怪的是,这对我来说没有任何意义,因为只有 1 个文本输入团队 ID(共 3 个)失败。其他 2 成功。
我的代码中缺少什么吗?任何帮助/线索都会非常有帮助。
谢谢。
解决方法
您的 TS 代码中有一个拼写错误。
在 TS 代码中你写了 teamdId
但在你的 html 中你写了 teamId
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。