import { Component, OnInit, OnDestroy } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { NgbActiveModal, NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; import { JhiEventManager } from 'ng-jhipster'; import { User, UserService } from 'app/core'; @Component({ selector: 'jhi-user-mgmt-delete-dialog', templateUrl: './user-management-delete-dialog.component.html' }) export class UserMgmtDeleteDialogComponent { user: User; constructor(private userService: UserService, public activeModal: NgbActiveModal, private eventManager: JhiEventManager) {} clear() { this.activeModal.dismiss('cancel'); } confirmDelete(login) { this.userService.delete(login).subscribe(response => { this.eventManager.broadcast({ name: 'userListModification', content: 'Deleted a user' }); this.activeModal.dismiss(true); }); } } @Component({ selector: 'jhi-user-delete-dialog', template: '' }) export class UserDeleteDialogComponent implements OnInit, OnDestroy { private ngbModalRef: NgbModalRef; constructor(private route: ActivatedRoute, private router: Router, private modalService: NgbModal) {} ngOnInit() { this.route.data.subscribe(({ user }) => { setTimeout(() => { this.ngbModalRef = this.modalService.open(UserMgmtDeleteDialogComponent as Component, { size: 'lg', backdrop: 'static' }); this.ngbModalRef.componentInstance.user = user.body; this.ngbModalRef.result.then( result => { this.router.navigate([{ outlets: { popup: null } }], { replaceUrl: true, queryParamsHandling: 'merge' }); this.ngbModalRef = null; }, reason => { this.router.navigate([{ outlets: { popup: null } }], { replaceUrl: true, queryParamsHandling: 'merge' }); this.ngbModalRef = null; } ); }, 0); }); } ngOnDestroy() { this.ngbModalRef = null; } }