Angular - Subgroup according to group id

Asked

Viewed 92 times

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>

Tela de visualização do grupo e subgrupo

  • <app-classification-subgroup-list [idGrupo]="idGroup" ></app-classification-subgroup-list> Try to do it this way...

  • @Lucasbrogni nothing happened. But I realized one thing. Let’s say that the id is going, As I call the getIdGroup?

  • 1

    There are a few ways, you can use ngOnChanges and call inside it, you can call in ngOnInit, you can subscribe to Event.

  • 1

    @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

  • I’ll put as an answer, then you mark as completed.

1 answer

0


<app-classification-subgroup-list [idGrupo]="idGroup" ></app-classification-subgroup-list> Try to do so... to pass the id to the subgroup and use the ngOnChanges to call the method.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.