mirror of https://github.com/abpframework/abp.git
3 changed files with 50 additions and 0 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 DebounceDirective 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,18 @@ |
|||||
|
import { Directive, ElementRef, EventEmitter, OnInit, Output, Renderer2 } from '@angular/core'; |
||||
|
import { fromEvent } from 'rxjs'; |
||||
|
|
||||
|
@Directive({ |
||||
|
selector: '[click.stop]', |
||||
|
}) |
||||
|
export class StopPropagationDirective implements OnInit { |
||||
|
@Output('click.stop') stopPropEvent = new EventEmitter<MouseEvent>(); |
||||
|
|
||||
|
constructor(private renderer: Renderer2, private el: ElementRef) {} |
||||
|
|
||||
|
ngOnInit(): void { |
||||
|
fromEvent(this.el.nativeElement, 'click').subscribe((event: MouseEvent) => { |
||||
|
event.stopPropagation(); |
||||
|
this.stopPropEvent.emit(event); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue