72 lines
1.9 KiB
TypeScript
72 lines
1.9 KiB
TypeScript
import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
|
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
|
import { Subject } from 'rxjs';
|
|
import { takeUntil } from 'rxjs/operators';
|
|
import { take } from 'rxjs/operators';
|
|
|
|
import { fuseAnimations } from 'src/@fuse/animations';
|
|
|
|
import { FreeBoardService } from 'src/modules/infos/service/free-board.service';
|
|
import { FreeBoard } from 'src/modules/infos/model/free-board.model';
|
|
|
|
@Component({
|
|
selector: 'app-free-board-regist',
|
|
templateUrl: './free-board-regist.component.html',
|
|
styleUrls: ['./free-board-regist.component.scss'],
|
|
encapsulation: ViewEncapsulation.None,
|
|
animations: fuseAnimations
|
|
})
|
|
export class FreeBoardRegistComponent implements OnInit, OnDestroy {
|
|
private unsubscribeAll: Subject<any>;
|
|
|
|
registForm: FormGroup;
|
|
|
|
constructor(
|
|
private fb: FormBuilder,
|
|
private freeboardService: FreeBoardService
|
|
) {
|
|
// Set the private defaults
|
|
this.unsubscribeAll = new Subject();
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------------------------------
|
|
// @ Lifecycle hooks
|
|
// -----------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* On init
|
|
*/
|
|
ngOnInit(): void {
|
|
// Subscribe to update order on changes
|
|
this.registForm = this.fb.group({
|
|
title: ['', [Validators.required]],
|
|
contents: ['', Validators.required]
|
|
});
|
|
}
|
|
|
|
/**
|
|
* On destroy
|
|
*/
|
|
ngOnDestroy(): void {
|
|
// Unsubscribe from all subscriptions
|
|
this.unsubscribeAll.next();
|
|
this.unsubscribeAll.complete();
|
|
}
|
|
|
|
onSubmit(): void {
|
|
let board: FreeBoard = <FreeBoard>this.registForm.value;
|
|
console.log(board);
|
|
this.freeboardService
|
|
.regist(board)
|
|
.pipe(take(1))
|
|
.subscribe(
|
|
res => {
|
|
console.log(res);
|
|
},
|
|
err => {
|
|
console.log(err);
|
|
}
|
|
);
|
|
}
|
|
}
|