0
I need to generate the subgroup according to the one selected in the group. I managed to go to present the id that was selected in html, I could not pass this value to getid.
I’m using Angular 6 + primeNg
Component group
grupo: Group[];
@Output() idSelecionado = new EventEmitter();
ngOnInit() { this.getListGroup();}
// Busca todos os grupos já cadastrados
getListGroup() {
this.service.getAllGroup()
.subscribe(data => {
this.grupo = data;
console.log(data);
});
}
// retorna o id que foi selecionado na lista
onRowSelect(event) {
this.idSelecionado.emit(event.data.id);
}
Component Subgroup
subgrupo: Subgroup[];
@Input() idGrupo: any;
getIdGroup() {
this.service.getIdSubgroup(this.idGrupo)
.subscribe(data => {
this.subgrupo = data;
});
}
Parent html Component
idGroup: any;
@Output() idTest = new EventEmitter();
aoSelecionar(id) {
this.idGroup = id;
console.log(`O componente classificationn escutou o id: ${id}` );
}
html that is presenting the others
<div class="ui-g-6">
<app-classification-group-form></app-classification-group-form>
<app-classification-group-list (idSelecionado)='aoSelecionar($event)'></app-classification-group-list>
</div>
<div class="ui-g-6">
<app-classification-subgroup-form></app-classification-subgroup-form>
<app-classification-subgroup-list ></app-classification-subgroup-list>
Escutando {{idGroup}}
</div>
<app-classification-subgroup-list [idGrupo]="idGroup" ></app-classification-subgroup-list>
Try to do it this way...– Lucas Brogni
@Lucasbrogni nothing happened. But I realized one thing. Let’s say that the id is going, As I call the getIdGroup?
– Cleriston Lincoln
There are a few ways, you can use ngOnChanges and call inside it, you can call in ngOnInit, you can subscribe to Event.
– Lucas Brogni
@Lucasbrogni vlw worked here. I didn’t know this ngOnChenges, I went now, tested and worked. This YT video explains well. https://www.youtube.com/watch?v=a7heex6vqUM
– Cleriston Lincoln
I’ll put as an answer, then you mark as completed.
– Lucas Brogni