source: bus-n-go-pavel-216049/bus-n-go-frontend/src/app/components/tickets-buy/tickets-buy.component.ts@ bfb90dd

Last change on this file since bfb90dd was baf4cc4, checked in by ppaunovski <paunovskipavel@…>, 3 months ago

split group project and individual project into two separate folders

  • Property mode set to 100644
File size: 1.5 KB
Line 
1import {Component, OnInit} from '@angular/core';
2import {MatSelectChange, MatSelectModule} from '@angular/material/select';
3import {MatInputModule} from '@angular/material/input';
4import {MatFormFieldModule} from '@angular/material/form-field';
5import {TicketTypeService} from "../../services/ticket-type/ticket-type.service";
6import {Tipbilet} from "../../model/Tipbilet";
7import {MatButtonModule} from '@angular/material/button';
8import {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})
17export 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}
Note: See TracBrowser for help on using the repository browser.