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 {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; |
||||
import {DomSanitizer} from "@angular/platform-browser"; |
import {DomSanitizer} from "@angular/platform-browser"; |
||||
|
import {IOService} from "../../services/IOService"; |
||||
|
import {Subscription} from "rxjs"; |
||||
|
|
||||
@Component({ |
@Component({ |
||||
selector: "app-abs-app", |
selector: "app-abs-app", |
||||
template: "" |
template: "" |
||||
}) |
}) |
||||
export abstract class AbsApp { |
export abstract class AbsApp implements OnInit, OnDestroy { |
||||
|
sub?: Subscription; |
||||
constructor(@Inject(MAT_DIALOG_DATA) public data: any, |
constructor(@Inject(MAT_DIALOG_DATA) public data: any, |
||||
protected ref: MatDialogRef<any>, |
protected ref: MatDialogRef<any>, |
||||
public sanitazer: DomSanitizer) { |
public sanitazer: DomSanitizer, |
||||
|
public io: IOService) { |
||||
} |
} |
||||
|
|
||||
@HostListener('document:keydown.escape', ['$event']) |
ngOnDestroy(): void { |
||||
onEscapeKeydown(event: KeyboardEvent) { |
if (this.sub) this.sub.unsubscribe(); |
||||
this.ref.close() |
} |
||||
|
|
||||
|
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