清除Angular表格后的黄色输入字段

时间:2017-06-14 17:05:06

标签: angular

我在整个应用程序中遇到过这种情况。当我清除表单时,第一个表单元素将始终保持黄色背景。我一直无法找到解决方法。

enter image description here

我尝试了以下内容:

public submit(form: NgForm) {
  this.spinner.show();

  this.httpUtils.hasUser(this.model)
    .subscribe(
      _data => {
        if (_data['success'] === false) {
          this.spinner.hide();
          this.alert.add(new Notification('error', Constants.USER_NOT_FOUND_MS, 12000));
          form.reset();
        } else {
          console.log(_data);
          this._data['data']['user'] = _data;
          this.spinner.hide();
          this.close();
          this.setup.next(_data);
        }
      }, 
      _error => {

      }
    );
}

我也试过从表单元素调用reset:

<form #form="ngForm" (submit)="submit(form); form.resetForm()" novalidate>
  <div class="form-element">
    <label for="email">Email</label>
    <input
        [(ngModel)]="model.username"
        #email="ngModel"
        type="email"
        name="email"
        required>
        <div
            *ngIf="email.invalid && email.touched"
            class="alert alert-invalid">
        is required
        </div>
    </div>
    <div class="form-action-buttons btn-multi">
    <button
        *ngIf="cancelable"
        (click)="cancel()"
        type="button"
        class="btn btn-mid-gray">
        Cancel
    </button>
    <button
        [disabled]="!form.valid"
        type="submit"
        class="btn btn-pirmary-light">
        Send
    </button>
  </div>
</form>

form.resetForm();

0 个答案:

没有答案