show component
This commit is contained in:
38
src/app/modules/shows/new/new.component.ts
Normal file
38
src/app/modules/shows/new/new.component.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {ShowDataService} from '../services/show-data.service';
|
||||
import {Observable} from 'rxjs';
|
||||
import {Show} from '../services/show';
|
||||
import {ShowService} from '../services/show.service';
|
||||
import {FormControl, FormGroup, Validators} from '@angular/forms';
|
||||
import {Router} from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-new',
|
||||
templateUrl: './new.component.html',
|
||||
styleUrls: ['./new.component.less']
|
||||
})
|
||||
export class NewComponent implements OnInit {
|
||||
public shows$: Observable<Show[]>;
|
||||
public showTypePublic = ShowService.SHOW_TYPE_PUBLIC;
|
||||
public showTypePrivate = ShowService.SHOW_TYPE_PRIVATE;
|
||||
public form: FormGroup;
|
||||
|
||||
constructor(private showService: ShowService, showDataService: ShowDataService, private router: Router) {
|
||||
this.shows$ = showDataService.list$();
|
||||
}
|
||||
|
||||
public ngOnInit(): void {
|
||||
this.form = new FormGroup({
|
||||
date: new FormControl(null, Validators.required),
|
||||
showType: new FormControl(null, Validators.required),
|
||||
})
|
||||
}
|
||||
|
||||
public async onSave() {
|
||||
this.form.markAllAsTouched();
|
||||
if (!this.form.valid) return;
|
||||
|
||||
const id = await this.showService.new$(this.form.value);
|
||||
await this.router.navigateByUrl('/shows/' + id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user