Commit 2c99cfa4ca5099e8e81d93e108c6b30de7f15e5e
1 parent
8467eb3d10
Exists in
master
Agregados fnciones
Showing
1 changed file
with
11 additions
and
2 deletions
 
Show diff stats
src/app/sidebar/sidebar.component.ts
| 1 | import { Component, OnInit } from '@angular/core'; | 1 | import { Component, OnInit } from '@angular/core'; | 
| 2 | 2 | ||
| 3 | @Component({ | 3 | @Component({ | 
| 4 | selector: 'app-sidebar', | 4 | selector: 'app-sidebar', | 
| 5 | templateUrl: './sidebar.component.html', | 5 | templateUrl: './sidebar.component.html', | 
| 6 | styleUrls: ['./sidebar.component.scss'] | 6 | styleUrls: ['./sidebar.component.scss'] | 
| 7 | }) | 7 | }) | 
| 8 | export class SidebarComponent implements OnInit { | 8 | export class SidebarComponent implements OnInit { | 
| 9 | 9 | ||
| 10 | private cont: number = 1; | 10 | private cont: number = 1; | 
| 11 | private min: number = 1; | 11 | private min: number = 1; | 
| 12 | private max: number =50; | 12 | private max: number =50; | 
| 13 | 13 | ||
| 14 | private productos = [ | 14 | private productos = [ | 
| 15 | { | 15 | { | 
| 16 | "id": 1, | 16 | "id": 1, | 
| 17 | "desc": "Galletas Oreo", | 17 | "desc": "Galletas Oreo", | 
| 18 | "cod": 225412, | 18 | "cod": 225412, | 
| 19 | "precio": 15, | 19 | "precio": 15, | 
| 20 | "img": "./assets/descarga.jpg", | 20 | "img": "./assets/descarga.jpg", | 
| 21 | "cantidad": 1 | 21 | "cantidad": 1 | 
| 22 | }, | 22 | }, | 
| 23 | { | 23 | { | 
| 24 | "id": 2, | 24 | "id": 2, | 
| 25 | "desc": "Coca cola 500ml", | 25 | "desc": "Coca cola 500ml", | 
| 26 | "cod": 512632, | 26 | "cod": 512632, | 
| 27 | "precio": 40, | 27 | "precio": 40, | 
| 28 | "img": "./assets/descarga.jpg", | 28 | "img": "./assets/descarga.jpg", | 
| 29 | "cantidad": 1 | 29 | "cantidad": 1 | 
| 30 | }, | 30 | }, | 
| 31 | { | 31 | { | 
| 32 | "id": 3, | 32 | "id": 3, | 
| 33 | "desc": "Pancho grande", | 33 | "desc": "Pancho grande", | 
| 34 | "cod": 775987, | 34 | "cod": 775987, | 
| 35 | "precio": 45, | 35 | "precio": 45, | 
| 36 | "img": "./assets/descarga.jpg", | 36 | "img": "./assets/descarga.jpg", | 
| 37 | "cantidad": 1 | 37 | "cantidad": 1 | 
| 38 | } | 38 | } | 
| 39 | ]; | 39 | ]; | 
| 40 | 40 | ||
| 41 | constructor() { } | 41 | constructor() { } | 
| 42 | 42 | ||
| 43 | ngOnInit() { | 43 | ngOnInit() { | 
| 44 | this.getProductosCarrito(); | 44 | this.getProductosCarrito(); | 
| 45 | } | 45 | } | 
| 46 | 46 | ||
| 47 | getProductosCarrito(){ | 47 | getProductosCarrito(){ | 
| 48 | return this.productos; | 48 | return this.productos; | 
| 49 | 49 | ||
| 50 | } | 50 | } | 
| 51 | 51 | ||
| 52 | public aumentarContador(cant){ | 52 | public aumentarContador(cant){ | 
| 53 | console.log("llego"); | 53 | console.log("llego"); | 
| 54 | for (const i of this.productos) { | 54 | for (const i of this.productos) { | 
| 55 | if (cant === this.max) { | 55 | if (cant === this.max) { | 
| 56 | return i.cantidad; | 56 | return i.cantidad; | 
| 57 | } else{ | 57 | } else{ | 
| 58 | ++i.cantidad | 58 | ++i.cantidad | 
| 59 | return i.cantidad; | 59 | return i.cantidad; | 
| 60 | } | 60 | } | 
| 61 | } | 61 | } | 
| 62 | |||
| 62 | // if (this.cont === this.max) { | 63 | // if (this.cont === this.max) { | 
| 63 | // this.cont; | 64 | // this.cont; | 
| 64 | // return this.cont; | 65 | // return this.cont; | 
| 65 | // } else { | 66 | // } else { | 
| 66 | // ++this.cont; | 67 | // ++this.cont; | 
| 67 | // return this.cont; | 68 | // return this.cont; | 
| 68 | // } | 69 | // } | 
| 69 | 70 | ||
| 70 | } | 71 | } | 
| 72 | aumentarContador2(index){ | ||
| 73 | for (let i = 0; i < this.productos.length; i++) | ||
| 74 | if (i === index) { | ||
| 75 | for (const pr of this.productos) { | ||
| 76 | |||
| 77 | } | ||
| 78 | } | ||
| 79 | } | ||
| 71 | 80 | ||
| 72 | decrementarContador(){ | 81 | decrementarContador(){ | 
| 73 | if (this.cont === this.min) { | 82 | if (this.cont === this.min) { | 
| 74 | this.cont; | 83 | this.cont; | 
| 75 | return this.cont; | 84 | return this.cont; | 
| 76 | } else { | 85 | } else { | 
| 77 | --this.cont; | 86 | --this.cont; | 
| 78 | return this.cont; | 87 | return this.cont; | 
| 79 | } | 88 | } | 
| 80 | } | 89 | } | 
| 81 | 90 | ||
| 82 | deleteProducto(index){ | 91 | deleteProducto(index){ | 
| 83 | for (let i = 0; i < this.productos.length; i++) | 92 | for (let i = 0; i < this.productos.length; i++) | 
| 84 | if (i === index) { | 93 | if (i === index) { | 
| 85 | this.productos.splice(i,1); | 94 | this.productos.splice(i,1); | 
| 86 | return this.productos ; | 95 | return this.productos ; | 
| 87 | } | 96 | } | 
| 88 | 97 | ||
| 89 | } | 98 | } | 
| 90 | } | 99 | } | 
| 91 | 100 |