【发布时间】:2021-03-17 04:41:10
【问题描述】:
我正在尝试制作一个可重用的输入组件,但我在控制台上收到此错误。 “ERROR 错误:找不到具有未指定名称属性的控件”。
这是我的注册类文件: ......
authForm = new FormGroup(
{
username: new FormControl(
'',
[
Validators.required,
Validators.minLength(3),
Validators.maxLength(20),
Validators.pattern(/[⌃a-z0-9]+$/),
],
......
这是我的注册模板:
<form [formGroup]="authForm" class="ui form">
<app-input
label="Username"
[control]="authForm.get('username')"
></app-input>
.......
这是我的输入类文件:
import { Component, OnInit, Input } from '@angular/core';
import { FormControl } from '@angular/forms';
@Component({
selector: 'app-input',
templateUrl: './input.component.html',
styleUrls: ['./input.component.css'],
})
export class InputComponent implements OnInit {
@Input() label: string;
@Input() control: FormControl;
constructor() {}
.......
这是我的输入模板文件:
<label>{{ label }}</label>
<input type="text" [formControl]="control" />
【问题讨论】:
标签: angular angular-reactive-forms reactive-forms