- 添加指令, 解析
boolean
值
import {Directive, ElementRef, Input} from "@angular/core";
@Directive({selector: '[isFocus]'})
export class IsFocusDirective {
constructor(private elementRef: ElementRef) {
}
@Input() set isFocus(isFocus: boolean) {
if (isFocus) {
this.elementRef.nativeElement.focus();
}
}
}
- html引入, 配合
(blur)
方法使用效果更佳
<input nz-input [(ngModel)]="name" name="someName" *ngIf="section.nameShow" [isFocus]="section.nameShow" (blur)="section.nameShow = false;" />
PS: 如果我的文章帮到了你, 免费的赞走一个呗~
网友评论