I'm following a online course but I have lots of problems with that.
I depends on I put on my code I get
type 'abstractcontrol' is missing the following properties from type 'formcontrol': registerOnChange, registerOnDisable, _applyFormState
or
type Abstractcontrol is not assignable to type formcontrol
In the TS of my Component I have
import { Component, EventEmitter, OnInit, Output } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { DestinoViaje } from '../models/destino-viaje.model';
@Component({
selector: 'app-form-destino-viaje',
templateUrl: './form-destino-viaje.component.html',
styleUrls: ['./form-destino-viaje.component.css']
})
export class FormDestinoViajeComponent implements OnInit {
@Output() onItemAdded: EventEmitter<DestinoViaje>;
fg: FormGroup;
constructor(fb: FormBuilder) {
this.onItemAdded = new EventEmitter();
this.fg = fb.group({
nombre: [''],
url: ['']
});
console.log(this.fg);
}
ngOnInit(): void {
}
guardar(nombre: string, url: string): boolean {
let d = new DestinoViaje(nombre, url);
this.onItemAdded.emit(d);
return false;
}
}
and in the HTML of my Component I Have
<form
[formGroup]="fg"
(ngSubmit)="guardar(
fg.controls['nombre'].value,
fg.controls['url'].value
)">
<div class="form-group">
<label for="nombre">Nombre</label>
<input type="text" class="form-control"
id="nombre" placeholder="Ingresar nombre..."
[formControl]="fg.controls['nombre']">
</div>
<div class="form-group">
<label for="Imagen Url">Imagen Url</label>
<input type="text" class="form-control"
id="imagenUrl" placeholder="Ingresar url..."
[formControl]="fg.controls['url']">
</div>
<button type="submit" class="btn btn-primary">Guardar!</button>
</form>
I'm not sure in which version the example is, but I'm using Angular 11.05
Thanks in advance.
Regards
Nicolas