Skip to content

Instantly share code, notes, and snippets.

@TiagoNunesDeveloper
Last active October 7, 2017 01:50
Show Gist options
  • Save TiagoNunesDeveloper/6426e5e77f5a2400bba9126e365b6bc9 to your computer and use it in GitHub Desktop.
Save TiagoNunesDeveloper/6426e5e77f5a2400bba9126e365b6bc9 to your computer and use it in GitHub Desktop.
@output EventEmitter
<jad-estudante *ngFor="let itemEstudante of estudantes" [estudante]="itemEstudante"></jad-estudante>
<jad-button *ngIf="!estudantes" (estudantesGet)="getEstudante($event)"></jad-button>
import { Component } from '@angular/core';
import { Estudante } from './estudante.model';
import { EstudanteService } from './estudante.service';
@Component({
selector: 'jad-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
public estudantes: Estudante[];
constructor() {}
public getEstudante(estudantes) {
this.estudantes = estudantes;
}
}
<button type="button" (click)="start()">Get Estudantes</button>
import { EstudanteService } from './../estudante.service';
import { Estudante } from './../estudante.model';
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
@Component({
selector: 'jad-button',
templateUrl: './button.component.html',
styleUrls: ['./button.component.css'],
})
export class ButtonComponent implements OnInit {
@Output()
estudantesGet: EventEmitter<Estudante[]> = new EventEmitter<Estudante[]>();
constructor(private service: EstudanteService) {}
ngOnInit() {}
public start(): void {
this.service.getAllEstudantes().then(a => this.estudantesGet.emit(a));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment