import { AfterViewInit , Component , Inject } from '@angular/core' ; import { MAT_DIALOG_DATA , MatDialogRef } from "@angular/material/dialog" ; import { Course } from "../model/course" ; import { FormBuilder , Validators , FormGroup } from "@angular/forms" ; import * as moment from 'moment' ; import { CoursesService } from '../services/courses.service' ; import { LoadingService } from '../loading/loading.service' ; import { MessagesService } from '../messages/messages.service' ; import { throwError } from 'rxjs' ; import { catchError } from 'rxjs/operators' ; import { CoursesStore } from '../services/courses.store' ; @ Component ( { selector : 'course-dialog' , templateUrl : './course-dialog.component.html' , styleUrls : [ './course-dialog.component.css' ] , providers : [ LoadingService , MessagesService ] } ) export class CourseDialogComponent { form : FormGroup ; course : Course ; constructor ( private fb , private dialogRef , @ Inject ( MAT_DIALOG_DATA ) course , private coursesStore , private messagesService ) { this . course = course ; this . form = fb . group ( { description : [ course . description , Validators . required ] , category : [ course . category , Validators . required ] , releasedAt : [ moment ( ) , Validators . required ] , longDescription : [ course . longDescription , Validators . required ] } ) ; } save ( ) { const changes = this . form . value ; this . coursesStore . saveCourse ( this . course . id , changes ) . subscribe ( ) ; this . dialogRef . close ( changes ) ; } close ( ) { this . dialogRef . close ( ) ; } }