1 | import {Component, OnInit} from '@angular/core';
|
---|
2 | import {MatSelectChange, MatSelectModule} from '@angular/material/select';
|
---|
3 | import {MatInputModule} from '@angular/material/input';
|
---|
4 | import {MatFormFieldModule} from '@angular/material/form-field';
|
---|
5 | import {TicketTypeService} from "../../services/ticket-type/ticket-type.service";
|
---|
6 | import {Tipbilet} from "../../model/Tipbilet";
|
---|
7 | import {MatButtonModule} from '@angular/material/button';
|
---|
8 | import {TicketService} from "../../services/ticket/ticket.service";
|
---|
9 |
|
---|
10 | @Component({
|
---|
11 | selector: 'app-tickets-buy',
|
---|
12 | standalone: true,
|
---|
13 | imports: [MatFormFieldModule, MatInputModule, MatSelectModule, MatButtonModule],
|
---|
14 | templateUrl: './tickets-buy.component.html',
|
---|
15 | styleUrl: './tickets-buy.component.css'
|
---|
16 | })
|
---|
17 | export class TicketsBuyComponent implements OnInit {
|
---|
18 | types: Tipbilet[] = []
|
---|
19 | selectedType: number | undefined;
|
---|
20 |
|
---|
21 | constructor(private ticketTypesService: TicketTypeService, private ticketService: TicketService) {
|
---|
22 | }
|
---|
23 |
|
---|
24 | ngOnInit(): void {
|
---|
25 | this.ticketTypesService.getTypes().subscribe({
|
---|
26 | next: response => {
|
---|
27 | console.log(response)
|
---|
28 | this.types = response
|
---|
29 | }
|
---|
30 | })
|
---|
31 | }
|
---|
32 |
|
---|
33 | protected readonly onsubmit = onsubmit;
|
---|
34 |
|
---|
35 | onSubmit() {
|
---|
36 | if (this.selectedType)
|
---|
37 | this.ticketService.buyTicket({
|
---|
38 | type: this.selectedType,
|
---|
39 | }).subscribe({
|
---|
40 | next: response => {
|
---|
41 | console.log(response)
|
---|
42 | }
|
---|
43 | })
|
---|
44 | }
|
---|
45 |
|
---|
46 | onPick($event: MatSelectChange) {
|
---|
47 | console.log($event)
|
---|
48 | this.selectedType = $event.value
|
---|
49 | }
|
---|
50 | }
|
---|