Last active
May 19, 2020 08:02
-
-
Save michaelilyin/c71a9fd8f3b480ab4133433af6abeec7 to your computer and use it in GitHub Desktop.
Find an issue and propose decision
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; | |
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; | |
import { TasksService } from '../tasks.service'; | |
import { Location } from '@angular/common'; | |
interface TaskForm { | |
name: string; | |
description: string; | |
} | |
@Component({ | |
selector: 'hrh-tasks', | |
templateUrl: './tasks.component.html', | |
styleUrls: ['./tasks.component.scss'], | |
changeDetection: ChangeDetectionStrategy.OnPush | |
}) | |
export class TasksComponent implements OnInit { | |
form: FormGroup; | |
constructor( | |
private readonly fb: FormBuilder, | |
private readonly taskService: TasksService, | |
private readonly location: Location | |
) { | |
this.form = fb.group({ | |
name: this.fb.control('', Validators.required), | |
description: this.fb.control('', [Validators.required, Validators.maxLength(500)]) | |
}); | |
} | |
ngOnInit(): void {} | |
handleFormSubmit(form: TaskForm) { | |
this.taskService.createTask({ | |
name: form.name, | |
description: form.description | |
}); | |
this.location.back(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { Observable } from 'rxjs'; | |
import { HttpClient } from '@angular/common/http'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class TasksService { | |
constructor(private http: HttpClient) {} | |
createTask(body: { name: string; description: string }): Observable<unknown> { | |
return this.http.get<User[]>('/tasks', body); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment