Tengo este mensaje de error al intentar actualizar el vector de la red con el archivo HTML.
Aquí he utilizado los datos estáticos de la tabla para mostrar e importado de otro componente que muestra la tabla primeng y he añadido un botón de actualización con una función que redirige a otra página para la actualización de los datos.
El problema se ve en la primera línea en el archivo HTML es decir; [FormGroup] = myvehicle
He tratado de comprobar con un nombre de grupo de forma diferente, pero sigue siendo el problema es el mismo.
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: ['']
});
this.vehicle = [
{
id: 1 , vin: 'dsad231ff' , year : 2012 , brand: 'VW' , color: 'Orange'
},
{
id: 2 , vin: 'gwregre345' , year : 2011 , brand: 'Audi' , color: 'Black'
},
{
id: 3 , vin: 'h354htr' , year : 2005 , brand: 'Renault' , color: 'Gray'
},
{
id: 4, vin: 'j6w54qgh' , year : 2003 , brand: 'BMW', color: 'Blue'
},
{
id: 5, vin: 'hrtwy34' , year : 1995 , brand: 'Mercedes' , color: 'Orange'
}
];
debugger
this.activatedRoute.paramMap
.subscribe( params => {
this.id = +params.get('id');
});
this.vehicle.forEach(element => {
if (element.id === this.id) {
this.Data = element;
}
});
this.myvehicle.patchValue({
vin: this.Data.vin,
year: this.Data.year,
brand: this.Data.brand,
color: this.Data.color
});
}
}
<form [formGroup]=myvehicle>
<label >Vin:</label>
<input type=text [formControlName]=vin ><br><br>
<label >Year:</label>
<input type=text [formControlName]=year ><br><br>
<label >Brand:</label>
<input type=text [formControlName]=brand ><br><br>
<label >Color:</label>
<input type=text [formControlName]=color ><br><br>
</form>