13 changed files with 151 additions and 77 deletions
@ -1,19 +1,29 @@ |
|||
import {Component, HostListener, Inject} from "@angular/core"; |
|||
import {Component, HostListener, Inject, OnDestroy, OnInit} from "@angular/core"; |
|||
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; |
|||
import {DomSanitizer} from "@angular/platform-browser"; |
|||
import {IOService} from "../../services/IOService"; |
|||
import {Subscription} from "rxjs"; |
|||
|
|||
@Component({ |
|||
selector: "app-abs-app", |
|||
template: "" |
|||
}) |
|||
export abstract class AbsApp { |
|||
export abstract class AbsApp implements OnInit, OnDestroy { |
|||
sub?: Subscription; |
|||
constructor(@Inject(MAT_DIALOG_DATA) public data: any, |
|||
protected ref: MatDialogRef<any>, |
|||
public sanitazer: DomSanitizer) { |
|||
public sanitazer: DomSanitizer, |
|||
public io: IOService) { |
|||
} |
|||
|
|||
@HostListener('document:keydown.escape', ['$event']) |
|||
onEscapeKeydown(event: KeyboardEvent) { |
|||
this.ref.close() |
|||
ngOnDestroy(): void { |
|||
if (this.sub) this.sub.unsubscribe(); |
|||
} |
|||
|
|||
ngOnInit(): void { |
|||
this.sub = this.io.keys.subscribe((code) => { |
|||
if (code == "Enter") |
|||
this.ref.close(); |
|||
}) |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,13 @@ |
|||
import {HostListener, Injectable} from "@angular/core"; |
|||
import {BehaviorSubject} from "rxjs"; |
|||
|
|||
@Injectable({ |
|||
providedIn: 'root' |
|||
}) |
|||
export class IOService { |
|||
public keys = new BehaviorSubject(""); |
|||
|
|||
constructor() { |
|||
this.keys.subscribe((code) => console.log(code)) |
|||
} |
|||
} |
|||
Loading…
Reference in new issue