angular - 找不到名称为“[object Object]”的控件
问题描述
<form nz-form (ngSubmit)="handleCreate()" [formGroup]="form">
<nz-form-item *ngIf="errors && errors.length > 0" class="alert alert-error">
<nz-form-label *ngFor="let error of errors">• {{ error }}</nz-form-label>
</nz-form-item>
<nz-form-item *ngIf="!(errors && errors.length) && warnings && warnings.length > 0" class="alert alert-warning">
<nz-form-label *ngFor="let warning of warnings">{{ warning }}</nz-form-label>
</nz-form-item>
<nz-form-item>This action will create a task:</nz-form-item>
<nz-form-item>
<nz-form-item nz-row>
<nz-form-label nz-col nzSpan="6">
definition
</nz-form-label>
<div nz-col nzSpan="18">
<app-stream-dsl>{{ dsl }}</app-stream-dsl>
</div>
</nz-form-item>
<nz-form-item nz-row>
<nz-form-label nz-col nzSpan="6" nzRequired [nzFor]="name">
name
</nz-form-label>
<nz-form-control nz-col nzSpan="18" [nzValidateStatus]="form.controls.taskName.errors" nzHasFeedback>
<input nz-input class="form-control input-sm"
[id]="name"
[name]="name" [formControlName]="taskName"
type="text" placeholder="<Task Name>"/>
<nz-form-explain *ngIf="form.controls.taskName.errors">
The format of your task name is invalid. {{ form.controls.taskName.errors.validateTaskName.reason }}
</nz-form-explain>
</nz-form-control>
</nz-form-item>
在此处输入图像描述
构造函数(私有taskService:TasksService,私有fb:FormBuilder,私有notificationService:NzNotificationService,私有loggerService:LoggerService,私有bsModalRef:NzModalRef,私有路由器:路由器){this.form = fb.group({'taskName': this.taskName });enter code here
解决方案
这个问题与 Angular 中如何实现绑定有关。
要将静态字符串传递给组件,可以使用以下内容:
<app-component myProperty="value">
这会将字符串值传递给组件 myProperty 成员 @Input。
但是,要传入对象的值,必须使用 [ ] 括号。
<app-component [myProperty]="obj">
这会将对象/变量等的值绑定到 myProperty @Input。
考虑到这一点,我们将在第 28 行注意到反应式表单属性 formControlName 设置为对象 taskName 而不是字符串值(如属性所期望的)'taskName'。从属性中删除括号将解决您的问题。
26 <input nz-input class="form-control input-sm"
27 [id]="name"
28 [name]="name" formControlName="taskName"
29 type="text" placeholder="<Task Name>"/>
更多信息可以在Binding Syntax Angular 文档和FromControlName中找到
推荐阅读
- c# - 如何使用 Azure AD 在 WPF 应用程序中验证 Web api
- python - 如何连续更改文本颜色
- reactjs - 为什么相同数据下价格差异的百分比一直在变化?
- sql - 如何将复杂的表单/投票问题转换为 SQL 表?
- c++ - 如何使用 mingw32-make 在 Makefile 中正确包含外部头文件?
- javascript - 有什么方法可以知道点击了哪个按钮?
- terraform - 无法使用 terraform 获取 VM 的 vSphere Instance UUID
- django - 管理面板实例视图中的标签输入字段
- angular - 为什么 Angular 应用程序只能从 spring 服务器下载一些 svg 文件
- django - 将列名更改为当前月份