export class Empleado {
nombre:string = "";
apellido:string = "";
cargo:string = "";
salario:number = 0;
constructor(nombre:string,apellido:string,cargo:string,salario:number) {
this.nombre = nombre;
this.apellido = apellido;
this.cargo = cargo;
this.salario = salario;
}
}
En el html
<input type="text" name="nombre" id="nombre" [(ngModel)]="txtNombre">
...
<button type="submit" (click)="addEmpleado()">Dar de alta</button>
En el ts
arrEmpleados:Empleado[]=[];
addEmpleado() {
let empleadoAux = new Empleado(this.txtNombre,this.txtApellido,this.txtCargo,this.txtSalario);
this.arrEmpleados.push(empleadoAux);
}
txtNombre:string = "";
txtApellido:string = "";
txtCargo:string = "";
txtSalario:number = 0;

No hay comentarios:
Publicar un comentario