Answer the question
In order to leave comments, you need to log in
Writing to jSON DB?
import { Component, OnInit } from '@angular/core';
import {FormControl, FormGroup, Validators} from '@angular/forms';
import {TicketsService} from '../../share/service/tickets.service';
import {Tickets} from '../../share/models/tickets.model';
@Component({
selector: 'anv-list-buy',
templateUrl: './list-buy.component.html',
styleUrls: ['./list-buy.component.css']
})
export class ListBuyComponent implements OnInit {
form:FormGroup;
data:Tickets;
constructor(private ticketsService:TicketsService){}
ngOnInit() {
this.form=new FormGroup({
'payeer':new FormControl(null,[Validators.required,Validators.maxLength(7)]),
'email':new FormControl(null,[Validators.required,Validators.email]),
//'ticket':new FormControl(null,[Validators.required,Validators.max(7)])
});
}
onBuy(){
this.data.payeer=this.form.value.payeer;
this.data.email=this.form.value.email;
console.log(this.data);
this.ticketsService.setTickets(this.data);
}
}
export class Tickets {
constructor(
public email: string,
public payeer: string,
public win: boolean = false,
public id?: number
) {
}
}
import {HttpClient} from '@angular/common/http';
import {Observable} from 'rxjs';
import {Tickets} from '../models/tickets.model';
import {Injectable} from '@angular/core';
@Injectable()
export class TicketsService {
constructor(private http:HttpClient){}
getWinTickets():Observable<Tickets[]>{
return this.http.get<Tickets[]>('http://localhost:3000/tickets');
}
setTickets(ticket:Tickets):Observable<Tickets[]>{
console.log(ticket)
return this.http.put<Tickets[]>('http://localhost:3000/tickets',ticket);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question