@ContentChildren(NgControl, { descendants: true }) ngControls!: QueryList<FormControlName | FormControlDirective>;
@ContentChildren(NgControl, { descendants: true, read: ElementRef }) ngControlEls!: QueryList<ElementRef>;
/** 第一个校验不通过的控件索引 */
firstErIndex!: number;
/** 是否点击了提交按钮,没有就是no,点了就是ok */
isClicked = new BehaviorSubject('no');
constructor() { }
ngOnInit(): void { }
// ContentChildren通常只能在元素渲染完成后才能拿到实例
ngAfterViewInit(): void {
this.isClicked.pipe(debounceTime(150)).subscribe(res => {
if (res === 'ok') {
this.ngControls?.find((el, index) => {
if (el.status == 'INVALID') {
this.firstErIndex = index;
return true;
} else {
return false
}
});
if (this.firstErIndex !== undefined && this.firstErIndex !=
基于ngzorro 表单点击提交按钮,滚动到第一个校验不通过的控件
于 2023-02-02 09:27:25 首次发布