import { Component, EventEmitter, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { BsModalRef } from 'ngx-bootstrap'; import { ToastrService } from 'ngx-toastr'; import { UploadVideoService } from '../../../../services/upload.video.service'; @Component({ selector: 'app-delete-video', templateUrl: './delete-video.component.html', styleUrls: ['./delete-video.component.css'] }) export class DeleteVideoComponent implements OnInit { deleteVideoForm: FormGroup; allVideos: any[]; public event: EventEmitter = new EventEmitter(); constructor(public bsModalRef: BsModalRef,private fb:FormBuilder,private toastr: ToastrService, private uploadVideoService: UploadVideoService) { } ngOnInit() { this.uploadVideoService.getVideos().subscribe( videos => { this.allVideos = videos['data'] as any[]; }); this.deleteVideoForm = this.fb.group({ file_name: [, Validators.required], }); } onDelete() { if(this.deleteVideoForm.valid) { this.uploadVideoService.deleteVideo(this.deleteVideoForm.get('file_name').value).subscribe((result: { status: string, message: string, data }) => { if (result.status === 'success') { this.toastr.success('Selected video is deleted'); this.bsModalRef.hide(); } }, (error) => { this.toastr.error("Something Went Wrong! Please try to refresh"); this.bsModalRef.hide(); }, );} else this.deleteVideoForm.get('file_name').markAllAsTouched(); } get file_name() { return this.deleteVideoForm.get('file_name') } }