Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
¿Por qué no puedo acceder al valor de Output EventEmitter de modal?

Tengo un componente modal suministrado a través de un servicio a mi componente principal. El modal tiene una salida que parece que debería desencadenar un evento que pasa una cadena.

Solo estoy tratando de ejecutar un código si se confirma el modal, pero no he podido conectarme al evento que supuestamente se emite. ¿Qué me estoy perdiendo?

[modal.componente.ts]

 export class ModalComponent implements OnInit { ... @Output() onAccepted = new EventEmitter<string>(); @Output() onDeclined = new EventEmitter<string>(); @Input() id!: string; private element: any; constructor(private modalService: ModalService, private el: ElementRef) { this.element = el.nativeElement; } ngOnInit(): void { // ensure id attribute exists if (!this.id) { console.error('modal must have an id'); return; } // add self (this modal instance) to the modal service so it's accessible from controllers this.modalService.add(this); } accept() { this.onAccepted.emit("Accepted"); this.close(); } ... // remove self from modal service when component is destroyed ngOnDestroy(): void { this.modalService.remove(this.id); this.element.remove(); } }

[ modal.service.ts ]

 @Injectable({ providedIn: 'root' }) export class ModalService { private modals: any[] = []; add(modal: any) { // add modal to array of active modals this.modals.push(modal); } remove(id: string) { // remove modal from array of active modals this.modals = this.modals.filter(x => x.id !== id); } open(id: string) { // open modal specified by id const modal = this.modals.find(x => x.id === id); modal.open(); } close(id: string) { // close modal specified by id const modal = this.modals.find(x => x.id === id); modal.close(); } }

[modal-parent.component.html]

 <modal id="assignAdminModal" title="Assign Administrator role" [message]="'Confirm assigning Administrator rights to this user?'" [showDecline]="true" [showAccept]="true" (onAccepted)="test($event)"></frisbo-modal>

[modal-parent.component.ts]

 test(event: any): void { console.log(event); }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!