使用FormControlName作为选择器进行聚焦

时间:2018-07-09 07:52:56

标签: angular

我有两个控件a和b,在b模糊的情况下,我编写了一个事件,该事件应检查a是否不为空。

我的表单是响应式表单,因此我没有添加id,是否可以使用formcontrolname而不是id或class来集中注意力。

bool canGoOn(Wizard* wizard)
{
    return wizard->hp > 0 && wizard->mp > 0; // just drop that if/else stuff around
}

这是我的职责。

2 个答案:

答案 0 :(得分:0)

Try Solution

HTML:

CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().build();           
customTabsIntent.launchUrl(context,Uri.parse(url));

TS:

<form [formGroup]="paymentForm">
    <input type="text" formControlName="a" placeholder="control a">
    <input type="text" (blur)="checkonBlur($event)" formControlName="b" placeholder="control b">

</form>

答案 1 :(得分:0)

import {
  Component,
  ElementRef
} from "@angular/core";


constructor(
    private el: ElementRef
  ) {}


scrollTo(el: Element) {
    if (el) {
      el.scrollIntoView({ behavior: "smooth" });
    }
  }

const invalidElements = this.el.nativeElement.querySelectorAll(
          ".ng-invalid"
        );

        if (invalidElements.length > 0) {
          this.scrollTo(invalidElements[1]); // invalidElements[0] is the total form element
        }
      }
相关问题