carrito.component.ts
1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { Component, OnInit } from '@angular/core';
import { Location } from '@angular/common';
import { ArticuloService } from 'src/app/services/articulo/articulo.service';
import { APP_SETTINGS } from 'src/etc/AppSettings';
import { trigger, state, style, transition, animate } from '@angular/animations';
import { IArticulo } from 'src/app/interfaces/IArticulo';
@Component({
selector: 'app-carrito',
templateUrl: './carrito.component.html',
styleUrls: ['./carrito.component.scss'],
animations: [
trigger('EnterLeave', [
state('flyIn', style({ transform: 'translateX(0)' })),
transition(':enter', [
style({ transform: 'translateX(-100%)' }),
animate('1s ease-in')
]),
transition(':leave', [
animate('1s ease-out', style({ transform: 'translateX(-100%)' }))
])
])
]
})
export class CarritoComponent implements OnInit {
urlImagenes = `${APP_SETTINGS.apiDeboSuite}/imagenes/`;
maxCantidad = 50;
constructor(
private location: Location,
public articuloService: ArticuloService,
) { }
ngOnInit() { }
deleteArticulo(index: number) {
this.articuloService.carrito.splice(index, 1);
}
substractCant(articulo: IArticulo) {
if (articulo.cantidad === 1) return;
articulo.cantidad--;
}
addCant(articulo: IArticulo) {
if (articulo.cantidad >= this.maxCantidad) return;
articulo.cantidad++;
}
goBack() {
this.location.back();
}
}