zoukankan      html  css  js  c++  java
  • [Angular2 Form] Understand the Angular 2 States of Inputs: Pristine and Untouched

    Angular 2’s ngModel exposes more than just validity, it even gives you the states of whether the input has been “touched” or changed. This lesson explains and compares those states so you can use them to make complex validity requirements.

      <form name="myForm2" #formRef2="ngForm" (ngSubmit)="onSubmit(formRef2.value)">
        <fieldset ngModelGroup="login">
          <legend>Login:</legend>
    
          Username: <input type="text" name="username" #usernameRef="ngModel" ngModel required>
          Password: <input type="password" name="password" #passwordRef="ngModel" ngModel required>
    
        </fieldset>
      </form>
      <div class="error-messages" *ngIf="!formRef2.valid">
        <span class="error-message" *ngIf="!usernameRef.untouched && usernameRef.errors?.required">Username is required</span>
        <span class="error-message" *ngIf="!passwordRef.untouched && passwordRef.errors?.required">password is required</span>
      </div>
      <pre>
        username pristine: {{usernameRef.pristine}}
        username dirty: {{usernameRef.dirty}}
        username untouched: {{usernameRef.untouched}}
        username touched: {{usernameRef.touched}}
        form value: {{formRef2.value | json}}
        form valid: {{formRef2.valid | json}}
      </pre>

    Github

  • 相关阅读:
    3. 尾缀
    Cocos工程命名规则整理(node部分)
    3.1-3.3 HBase Shell创建表
    2.11-2.12 HBase的数据迁移常见方式
    2.8-2.10 HBase集成MapReduce
    2.7 HBase架构深入剖析
    2.3-2.6 HBase java API
    2.1-2.2 HBase数据存储
    1.6-1.8 HBase表的物理模型
    1.4-1.5 HBase部署及基本使用
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5914166.html
Copyright © 2011-2022 走看看