import { Component, OnInit, OnChanges, SimpleChanges, Renderer2, Input, Output, EventEmitter, ElementRef } from '@angular/core'; import { Modal } from 'sigma-ng/modal'; @Component({ selector: 'modal-prompt', templateUrl: './prompt.component.html', styleUrls: ['./prompt.component.css'] }) export class ModalPromptComponent implements OnInit,OnChanges { @Input('modal-title') title: string = 'Title'; @Input() modal: Modal; @Input() value: string; @Input() progress: boolean; @Output() onconfirm: EventEmitter = new EventEmitter; @Output() onclose: EventEmitter = new EventEmitter; constructor(private element: ElementRef) { } ngOnInit(): void { if(this.modal) { this.modal.onchange = isopen => { if(isopen) { let element = this.element.nativeElement.querySelector('#input'); if(element) element.focus(); } } } } ngOnChanges(changes: SimpleChanges): void { } focus(btn:any) { if(this.modal.isopen) btn.focus(); } confirm() { this.onconfirm.emit(this.value); this.value = ''; } cancel() { this.value = ''; this.modal.close(); } }