<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>
enter image description here
构造函数(私有taskService:TasksService,
私人fb:FormBuilder,
私人notificationService:NzNotificationService,
私有loggerService:LoggerService,
私人bsModalRef:NzModalRef,
专用路由器:路由器){
this.form = fb.group({
'taskName':this.taskName
}); enter code here
答案 0 :(得分:2)
该问题与如何在Angular中实现绑定有关。
要将静态字符串传递到组件中,可以使用以下命令:
<app-component myProperty="value">
这会将字符串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