Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {Component, OnInit} from '@angular/core';
- import {FormControl, FormGroup, Validators} from '@angular/forms';
- import {Car} from '../../pojazdy/http-cars.model';
- import {HttpCarsService} from '../../pojazdy/http-cars.service';
- import {MatSnackBar} from '@angular/material';
- import {carStatus} from './carStatus.model';
- import {CarStatusService} from './car-status.service';
- import {HttpClient, HttpErrorResponse} from '@angular/common/http';
- import {ConfigService} from '../../../services/config.service';
- import {Observable} from 'rxjs';
- import {CarTypeService} from './car-type.service';
- import {carType} from './carType.model';
- @Component({
- selector: 'app-add-dialog1',
- templateUrl: './add-dialog1.component.html',
- styleUrls: ['./add-dialog1.component.scss']
- })
- export class AddDialog1Component implements OnInit {
- constructor(private httpCarsService: HttpCarsService,
- public snackBar: MatSnackBar,
- public carStatusService:CarStatusService,
- public carTypeService:CarTypeService
- ) { }
- car : Car=new Car();
- submitted = false;
- selected = null;
- statusList: Observable<carStatus[]>;
- carStatus: carStatus = new carStatus();
- typeList: Observable<carType[]>;
- carType: carType = new carType();
- ngOnInit() {
- this.submitted=false;
- this.carStatusService.getCarStatusList().subscribe(data => {
- this.statusList = data;
- });
- this.carTypeService.getCarTypeList().subscribe(data => {
- this.typeList = data;
- });
- }
- carsaveform=new FormGroup({
- mark:new FormControl('' , [Validators.required] ),
- model:new FormControl('' , [Validators.required] ),
- registrationNumber:new FormControl('' , [Validators.required,Validators.minLength(7),Validators.maxLength(7)] ),
- axes:new FormControl('',[Validators.required]),
- yearProduction:new FormControl('' , [Validators.required] ),
- datePurchase:new FormControl('' , [Validators.required ] ),
- dateReview:new FormControl('' , [Validators.required]),
- carType:new FormControl(),
- carStatus:new FormControl()
- });
- saveCar(saveCar){
- this.car=new Car();
- this.car.mark = this.Mark.value;
- this.car.model = this.Model.value;
- this.car.registrationNumber = this.RegistrationNumber.value;
- this.car.axes = this.Axes.value;
- this.car.yearProduction = this.YearProduction.value;
- this.car.datePurchase = this.DatePurchase.value;
- this.car.dateReview = this.DateReview.value;
- this.car.carType = this.CarType.value;
- this.car.carStatus = this.CarStatus.value;
- this.submitted = true;
- this.save();
- }
- save() {
- this.httpCarsService.createCar(this.car)
- .subscribe(data => console.log(data), error => console.log(error));
- this.car = new Car();
- }
- get Mark() {
- return this.carsaveform.get('mark');
- }
- get Model() {
- return this.carsaveform.get('model');
- }
- get RegistrationNumber() {
- return this.carsaveform.get('registrationNumber');
- }
- get Axes() {
- return this.carsaveform.get('axes');
- }
- get YearProduction() {
- return this.carsaveform.get('yearProduction');
- }
- get DatePurchase() {
- return this.carsaveform.get('datePurchase');
- }
- get DateReview() {
- return this.carsaveform.get('dateReview');
- }
- get CarType() {
- return this.carsaveform.get('carType');
- }
- get CarStatus() {
- return this.carsaveform.get('carStatus');
- }
- addCarForm(){
- this.submitted=false;
- this.carsaveform.reset();
- }
- openSnackBar(message: string, action: string) {
- this.snackBar.open(message, action, {
- duration: 2000,
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment