-1

Sou novata com Angular e preciso passar como parâmetro para o método "carregaProducao" o funcionário da vez no ngFor do meu HTML, porém não estou conseguindo, o console não imprime nada no console.log(producao1). Como seria a forma correta de fazer a passagem desse parâmetro para o método e após isso conseguir acessar os atributos de producao1?

@Component({
  selector: 'app-conecta-lista-ggrupo',
  templateUrl: './conecta-lista-ggrupo.component.html',
  styleUrls: ['./conecta-lista-ggrupo.component.css']
})
export class ConectaListaGgrupoComponent implements OnInit {

  gerenteId: string;
  gerenteGrupo: GerenteGrupo = new GerenteGrupo();
  gerenteGrupo1: GerenteGrupo[];
  funcionarios : Funcionarios[];
  funcis2: Funcionarios[];
  producao1: Producao[];
  producao2: Producao[];
  producao2$: Observable<Producao[]>;
  todaProducao: Producao[];
  recebeTodaProducao: Producao;
  contaProducao: number = 0;
  funcis = new Array<Funcionarios>();
  matricula: string;

  virgula: string = ",";


    gaugeType = "full";
    gaugeValue = this.contaProducao;
    gaugeValue1 = 10;
    gaugeValue2 = 20;
    gaugeValue3 = 30;
    gaugeMax = 20;
    gaugeLabel = "Processos orçados";
    gaugeAppendText = "de 18";
    gaugeSize = 200;
    gaugeSize1 = 150;
    gaugeCap = "round";
    gaugeThick = 10;

    thresholdConfig = {
      '0': {color: 'red'},
      '9': {color: 'orange'},
      '16': {color: 'green'}
  };

  constructor(private conectaServiceService : ConectaServiceService,
    private app: AppComponent,
    private route: ActivatedRoute) { 

      this.gerenteId = this.route.snapshot.params['id'];
      console.log(this.route);

    }

  ngOnInit() {

    this.conectaServiceService.getListGerenteGrupoString(this.route.snapshot.params['id']).subscribe(gerenteGrupo=> {
      this.gerenteGrupo = gerenteGrupo;

      this.carregaFuncionarios(gerenteGrupo);
      //this.gerenteGrupoParaArray(gerenteGrupo);
      console.log("teste");
      console.log(this.contaProducao);

    });

    //this.producao2$ = this.conectaServiceService.getListProducao();
    //console.log("producao2$: " + this.producao2$);
    //this.contaProducao = <HTMLInputElement>document.querySelector('#testaProducao');
    //this.carregaProducao;
    //this.contaProcessos;
    //this.carregaTodaProducao2();
    this.carregaTodaProducao();
    //this.carregaProducao(this.funcionarios);
    //console.log("producao2: " + this.producao2);
    //this.gerenteGrupoParaArray();
    this.adicionaFuncionarios;
    this.paraArray;
    //this.contaProducao = <HTMLInputElement>document.querySelector('#testaProducao');
    //this.contaProducao = this.contaProcessos;
    //this.acrescentaFuncionarios;
  }

  carregaGerenteSetorSelecionado(gerenteGrupo: GerenteGrupo){
    this.conectaServiceService.getListGerenteGrupoSelecionado(gerenteGrupo).subscribe(
      resposta => this.gerenteGrupo1 = resposta
    )
  }

  carregaFuncionarios(gerenteGrupo: GerenteGrupo) {
    console.log(gerenteGrupo);
    //this.gerenteArea.id
    this.conectaServiceService.getListFuncionariosPorGerenteGrupo(gerenteGrupo).subscribe(
      resposta => this.funcionarios = resposta

    )

  }
novoFuncionario: Funcionarios = new Funcionarios();


  carregaProducao(funcionarios: Funcionarios) {
    //console.log(funcionarios);
    this.conectaServiceService.getListProducaoPorFuncionario(funcionarios).subscribe(
      resposta => this.producao1 = resposta
    )
      console.log("producao1: " + this.producao1);
  }

Meu HTML:

<div class="container">
      <div class="row">
          <div class="col" *ngFor="let funcionario of funcionarios">
            <div class="card border-secondary mb-3" style="width: 15rem;" [routerLink]="['//listaProducao/', funcionario.id]">
             <!-- <ng-container *ngIf="producao2.filter(p.matricula === funcionario.matricula).length; let producoesCount"></ng-container>-->
                <img style="width: 80px; height: 80px;  margin-top: 10px; margin-right:10px;" class="rounded-circle" src="https://humanograma.intranet.bb.com.br/avatar/{{ funcionario.matricula }}">
                <div class="card-body" >
                    <p class="card-title">{{ funcionario.nome.split(" ", 1) }}</p>
                    <p class="card-text-func-matricula">{{ funcionario.matricula }} </p>
                    <p class="card-text-func-matricula">{{ carregaProducao(funcionario)}}  </p>
                    <!--<button (click)="carregaProducao(funcionarios)" class="btn btn-primary">Producao</button>-->
                      <div class="gauge" style="text-align: center">
                        <ngx-gauge [type]="gaugeType" 
                        [value]="funcionarios.producao.length" 
                        [max]="gaugeMax"
                        [label]="gaugeLabel"  
                        [append]="gaugeAppendText"
                        [size] = "gaugeSize1"
                        [cap] = "gaugeCap"
                        [thick] = "gaugeThick"
                        [thresholds]="thresholdConfig">
                        </ngx-gauge>
                      </div>  
                </div>
            </div>
          </div>
      </div>
  </div>

Meu service:

 getListFuncionariosPorGerenteGrupo(gerenteGrupo: GerenteGrupo){
    return this.http.get<Funcionarios[]>(environment.apiPath + '/api/funcionarios/gerenteGrupo/' + gerenteGrupo.id)
  }
  getListProducaoPorFuncionario(funcionarios: Funcionarios){
    return this.http.get<Producao[]>(environment.apiPath + '/api/producaoConecta/funcionarios/' + funcionarios.id)
  }
2
  • Mas,na assinatura do service está pegando o id do funcionário para fazer a requisição, logo, na chamada do service vc tbm tem que passar um id de um funcionário.
    – LeAndrade
    29/07/2019 às 18:20
  • Na chamada do service, eu passo um objeto funcionário como parâmetro, este objeto possui a propriedade id nele, que é passada na API como funcionários.id. O meu JSON está retornando com os dados corretos, mas como funcionários é um array com com vários funcionários, ele me retorna um array de produção e preciso pegar a produção de cada funcionário individualmente quando ele passa pelo ngFor. 29/07/2019 às 21:01

1 Resposta 1

-1

Você ta pegando o Array no click

(click)="carregaProducao(funcionarios)"

Sendo que você quer saber a produção daquele funcionário especifico não é? Então você tem passar só o funcionário por parâmetro e não o Array inteiro.

(click)="carregaProducao(funcionario)"

No ts a mesma coisa, talvez essa sua tipagem esteja diferente.

carregaProducao(funcionario) {
console.log(funcionario);
this.conectaServiceService.getListProducaoPorFuncionario(funcionario).subscribe(
  resposta => this.producao1 = resposta
)
  console.log("producao1: " + this.producao1);
}

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .