Last active
July 24, 2020 03:57
-
-
Save sommereder/a53d897ea64bae8c22cad9551466dd9a to your computer and use it in GitHub Desktop.
Get the outputs to/from the modal, by passing them as event emitter to the modal service and subscribe directly at the component opening the modal box.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, EventEmitter, Input, Output } from '@angular/core'; | |
@Component({ | |
selector: 'app-my-modal', | |
styleUrls: ['./my-modal.component.scss'], | |
template: ` | |
<p>{{content}}</p> | |
<button (click)="confirm()">OK</button> | |
`, | |
}) | |
export class MyModalComponent { | |
@Input() content!: string; | |
@Input() confirmation!: EventEmitter<boolean>; | |
constructor() {} | |
confirm() { | |
this.confirmation.emit(true); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, EventEmitter } from '@angular/core'; | |
@Component({ | |
selector: 'app-my-whateva', | |
styleUrls: ['./my-whateva.component.scss], | |
template: ` | |
<button (click)="doIt()">Do it!</button> | |
`, | |
}) | |
export class MyWhatevaComponent { | |
constructor( | |
private readonly _modalService: ModalService, | |
) {} | |
doIt() { | |
let confirmation:EventEmitter<boolean> = new EventEmitter<boolean>(); | |
confirmation.subscribe(next => console.log(next)); | |
this._modalService.create( | |
MyModalComponent, | |
{content: 'Wirklich löschen?'}, // inputs | |
{confirmation}, // outputs (as inputs) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment