mirror of https://github.com/abpframework/abp.git
13 changed files with 93 additions and 62 deletions
@ -0,0 +1,26 @@ |
|||
import { Directive, Output, Renderer2, ElementRef, OnInit, EventEmitter, Input } from '@angular/core'; |
|||
import { fromEvent } from 'rxjs'; |
|||
import { debounceTime } from 'rxjs/operators'; |
|||
import { takeUntilDestroy } from '@ngx-validate/core'; |
|||
|
|||
@Directive({ |
|||
selector: '[input.debounce]', |
|||
}) |
|||
export class InputEventDebounceDirective implements OnInit { |
|||
@Input() debounce: number = 300; |
|||
|
|||
@Output('input.debounce') debounceEvent = new EventEmitter<Event>(); |
|||
|
|||
constructor(private renderer: Renderer2, private el: ElementRef) {} |
|||
|
|||
ngOnInit(): void { |
|||
fromEvent(this.el.nativeElement, 'input') |
|||
.pipe( |
|||
debounceTime(this.debounce), |
|||
takeUntilDestroy(this), |
|||
) |
|||
.subscribe((event: Event) => { |
|||
this.debounceEvent.emit(event); |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
import { Directive, ElementRef, EventEmitter, OnInit, Output, Renderer2 } from '@angular/core'; |
|||
import { fromEvent } from 'rxjs'; |
|||
import { takeUntilDestroy } from '@ngx-validate/core'; |
|||
|
|||
@Directive({ |
|||
selector: '[click.stop]', |
|||
}) |
|||
export class ClickEventStopPropagationDirective implements OnInit { |
|||
@Output('click.stop') stopPropEvent = new EventEmitter<MouseEvent>(); |
|||
|
|||
constructor(private renderer: Renderer2, private el: ElementRef) {} |
|||
|
|||
ngOnInit(): void { |
|||
fromEvent(this.el.nativeElement, 'click') |
|||
.pipe(takeUntilDestroy(this)) |
|||
.subscribe((event: MouseEvent) => { |
|||
event.stopPropagation(); |
|||
this.stopPropEvent.emit(event); |
|||
}); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue