我尝试创建一个动态表单(所以你可以无限制地添加项目到列表),但不知何故我的列表的内容没有得到发送,因为它找不到路径控件:
无法通过路径找到控件:'list_items - > list_item'
我的组件:
@Component({
selector: 'app-list',
templateUrl: './list.component.html',
styleUrls: ['./list.component.css']
})
export class ListComponent implements OnInit {
listForm: FormGroup;
constructor(private nodeService: NodeService, private messageService: MessageService, private fb: FormBuilder,
private listService: ListService) {
this.listForm = this.fb.group({
title: ['', [Validators.required, Validators.minLength(5)]],
list_items: this.fb.array([
this.initListItem(),
])
});
}
initListItem() {
return this.fb.group({
list_item: ['']
});
}
initListItemType() {
return this.fb.group({
list_item_type: ['']
});
}
addListItem() {
const control = <FormArray>this.listForm.controls['list_items'];
control.push(this.initListItem());
}
Run Code Online (Sandbox Code Playgroud)
模板(list.component.html):
<h2>Add List </h2>
<form [formGroup]="listForm" novalidate (ngSubmit)="addList(listForm)"> …Run Code Online (Sandbox Code Playgroud) 当尝试使用 HTML 文件更新网格表时,我收到此错误消息。
在这里,我使用了静态数据来显示表格,并从显示 primeng 表的其他组件导入,并且我添加了一个更新按钮,该按钮具有重定向到另一个页面以更新数据的功能。
该问题出现在 HTML 文件的第一行中,即;[formGroup]="我的车辆"
我尝试使用不同的表单组名称进行检查,但问题仍然相同。
import { Component, OnInit } from '@angular/core';
import {Router, ActivatedRoute, Params} from '@angular/router';
import { FormBuilder, FormGroup } from '@angular/forms';
@Component({
selector: 'app-crud',
templateUrl: './crud.component.html',
})
export class CrudComponent implements OnInit {
myvehicle: FormGroup;
display: boolean;
id: number;
vin: any;
year: number;
brand: string;
color: string;
vehicle: any;
Data: any;
constructor(private activatedRoute: ActivatedRoute, private fb: FormBuilder) {
}
ngOnInit() {
this.myvehicle = this.fb.group({
vin: [''],
year: [''],
brand: [''],
color: …Run Code Online (Sandbox Code Playgroud)