首页 > 解决方案 > 找不到名称为“[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

解决方案


这个问题与 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中找到


推荐阅读