@40three/ngx-autofocus-directive 中文文档教程
ngx-autofocus-directive
html autofocus
属性是设置焦点的便捷方式。 问题是,它仅在第一次显示元素时起作用,而通常情况下不是我们在 SPA 中所期望的那样。 每次显示元素时,这个小指令都会设置焦点。
Installation
npm install --save @40three/ngx-autofocus-directive
Add Module
在每个使用包含 autofocus
属性的元素声明组件的角度模块中导入模块。
@NgModule({
imports: [
FtAutofocusModule,
]
})
Usage
<input type="text" autofocus />
<input type="text [attr.autofocus]="autofocusEnabled" />
<!-- every not null value, will add the autofocus attribute -->
<input type="text" [autofocus]="autofocusEnabled" />
ngx-autofocus-directive
The html autofocus
attribute is a handy way to set the focus. The problem is, that it works only the first time when an element is shown and that's normally not, what we expect in SPAs. This small directive sets the focus everytime the element is shown.
Installation
npm install --save @40three/ngx-autofocus-directive
Add Module
Import the module in every angular module that declares components using elements containing an autofocus
attribute.
@NgModule({
imports: [
FtAutofocusModule,
]
})
Usage
<input type="text" autofocus />
<input type="text [attr.autofocus]="autofocusEnabled" />
<!-- every not null value, will add the autofocus attribute -->
<input type="text" [autofocus]="autofocusEnabled" />