sql >> Base de Datos >  >> NoSQL >> MongoDB

Manejo del envío de dos parámetros en una llamada API en la aplicación Angular

Para hacer el código ordenado. Esto manejará múltiples parámetros.

onFilterReceived(para: any, type: string) {
    let body:any = {};
    body['services.workflow.status'] = 'consulting';
    if (type == 'lan')
        body['languages.primary'] =  { $in: para };
    if (type == 'nat')
        body['services.service'] =  { $in: para };

    this.filtersService.getByFilter(this.page, this.pagesize, body)
        .subscribe(resRecordsData => {
                       this.records = resRecordsData;
                   },
                   responseRecordsError => this.errorMsg = responseRecordsError
        );
}

En plantilla:

<list [records]="records" 
    (sendLanguage)="onFilterReceived($event, 'lan')"
    (sendNationality)="onFilterReceived($event, 'nat')">
</list>