Skip to content

Commit

Permalink
�62. @outputs y EventEmitter
Browse files Browse the repository at this point in the history
  • Loading branch information
verdizone committed Feb 25, 2021
1 parent 9bebfb9 commit e1d7e6c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/app/dbz/agregar/agregar.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Input } from '@angular/core';
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { Personajes } from '../interfaces/dbz.interface';

@Component({
Expand All @@ -8,20 +8,22 @@ import { Personajes } from '../interfaces/dbz.interface';

export class AgregarComponent {

@Input() personajes:Personajes[] = [];
// @Input() personajes:Personajes[] = [];

@Input() nuevo: Personajes = {
nombre: 'TETE',
poder: 100,
}

@Output() onNuevoPersonaje:EventEmitter<Personajes> = new EventEmitter<Personajes>();

agregar() {

if (this.nuevo.nombre.trim().length === 0) { return; }

console.log(this.nuevo);
// this.peronajes.push(this.nuevo);
this.personajes.push(this.nuevo);
this.onNuevoPersonaje.emit(this.nuevo);

this.nuevo = {
nombre: '',
poder: 0,
Expand Down
5 changes: 2 additions & 3 deletions src/app/dbz/main-page/main-page.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ <h1>Dragon Ball Z</h1>

<div class="col">
<app-agregar
[personajes]="personajes">
[nuevo]="nuevo">
</app-agregar>
(onNuevoPersonaje)="agregarNuevoPersonaje( $event )"
[nuevo]="nuevo"></app-agregar>
</div>
</div>

Expand Down
5 changes: 5 additions & 0 deletions src/app/dbz/main-page/main-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export class MainPageComponent {
}
];

agregarNuevoPersonaje(personaje:Personajes){
// console.log(personaje);
this.personajes.push(personaje);
}



}

0 comments on commit e1d7e6c

Please sign in to comment.