create new title
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import {Directive, ElementRef, Input} from "@angular/core";
|
||||
|
||||
@Directive({
|
||||
selector: "[autofocus]"
|
||||
})
|
||||
export class AutofocusDirective {
|
||||
private focus = true;
|
||||
|
||||
constructor(private el: ElementRef) {
|
||||
}
|
||||
|
||||
@Input() set autofocus(condition: boolean) {
|
||||
this.focus = condition !== false;
|
||||
}
|
||||
|
||||
public ngOnInit(): void {
|
||||
if (this.focus) {
|
||||
window.setTimeout(() => {
|
||||
this.el.nativeElement.focus();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import {NgModule} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {AutofocusDirective} from './autofocus.directive';
|
||||
|
||||
|
||||
@NgModule({
|
||||
declarations: [AutofocusDirective],
|
||||
exports: [
|
||||
AutofocusDirective
|
||||
],
|
||||
imports: [
|
||||
CommonModule
|
||||
]
|
||||
})
|
||||
export class AutofocusModule {
|
||||
}
|
||||
Reference in New Issue
Block a user