Commit a667c64fe16f51a3c04e6f7feb547076899a028b
1 parent
518aa41899
Exists in
master
timeout okey
Showing
1 changed file
with
17 additions
and
11 deletions
Show diff stats
src/app/components/pedidos-salientes/pedidos-salientes.component.ts
| 1 | import { Component, OnInit } from '@angular/core'; | 1 | import { Component, OnInit } from '@angular/core'; |
| 2 | import { ComandaService } from 'src/app/services/comanda.service'; | 2 | import { ComandaService } from 'src/app/services/comanda.service'; |
| 3 | 3 | ||
| 4 | @Component({ | 4 | @Component({ |
| 5 | selector: 'app-pedidos-salientes', | 5 | selector: 'app-pedidos-salientes', |
| 6 | templateUrl: './pedidos-salientes.component.html', | 6 | templateUrl: './pedidos-salientes.component.html', |
| 7 | styleUrls: ['./pedidos-salientes.component.scss'] | 7 | styleUrls: ['./pedidos-salientes.component.scss'] |
| 8 | }) | 8 | }) |
| 9 | export class PedidosSalientesComponent implements OnInit { | 9 | export class PedidosSalientesComponent implements OnInit { |
| 10 | 10 | ||
| 11 | private pedidosRecientes = []; | 11 | private pedidosRecientes = []; |
| 12 | private ciclo; | 12 | private cicloTime; |
| 13 | 13 | ||
| 14 | constructor(private comandaService: ComandaService) { } | 14 | constructor(private comandaService: ComandaService) { } |
| 15 | 15 | ||
| 16 | ngOnInit() { | 16 | ngOnInit() { |
| 17 | this.buscar(); | ||
| 18 | 17 | ||
| 19 | this.ciclo = setTimeout(() => { | 18 | this.buscar(); |
| 20 | this.buscar(); | 19 | this.ciclo(); |
| 21 | }, 5000) | ||
| 22 | } | 20 | } |
| 23 | 21 | ||
| 24 | ngOnDestroy() { | 22 | ngOnDestroy() { |
| 25 | 23 | ||
| 26 | clearTimeout(this.ciclo); | 24 | clearTimeout(this.cicloTime); |
| 27 | } | 25 | } |
| 28 | 26 | ||
| 29 | buscar() { | 27 | ciclo() { |
| 28 | |||
| 29 | this.cicloTime = setTimeout(() => { | ||
| 30 | 30 | ||
| 31 | this.buscar(); | ||
| 32 | this.ciclo(); | ||
| 33 | }, 5000) | ||
| 34 | } | ||
| 35 | |||
| 36 | buscar() { | ||
| 31 | this.comandaService | 37 | this.comandaService |
| 32 | .getPendientesEntrega() | 38 | .getPendientesEntrega() |
| 33 | .subscribe((pedidos: []) => { | 39 | .subscribe((pedidos: []) => { |
| 34 | 40 | ||
| 35 | this.pedidosRecientes = pedidos; | 41 | this.pedidosRecientes = pedidos; |
| 36 | }, console.log); | 42 | }, console.log); |
| 37 | } | 43 | } |
| 38 | 44 | ||
| 39 | rellenar(relleno, longitud) { | 45 | rellenar(relleno, longitud) { |
| 40 | relleno = '' + relleno; | 46 | relleno = '' + relleno; |
| 41 | while (relleno.length < longitud) { | 47 | while (relleno.length < longitud) { |
| 42 | relleno = '0' + relleno; | 48 | relleno = '0' + relleno; |
| 43 | } | 49 | } |
| 44 | return relleno; | 50 | return relleno; |
| 45 | } | 51 | } |