Angular 角度6模板驱动形式下的DOB验证

Angular 角度6模板驱动形式下的DOB验证,angular,Angular,我试图创建一个DOB字段,该字段需要有一个到{{currentdate}的最大值,我的方法是在TS文件中获取当前日期,并在HMTL'max'验证器中使用字符串插值,但是使用 date: Date = new Date(); <h1>{{date}}</h1> <form (ngSubmit)="onSignUp(f)" #f="ngForm"> <div class="form-group

我试图创建一个DOB字段,该字段需要有一个到{{currentdate}的最大值,我的方法是在TS文件中获取当前日期,并在HMTL'max'验证器中使用字符串插值,但是使用

  date: Date = new Date();
        <h1>{{date}}</h1>

        <form (ngSubmit)="onSignUp(f)" #f="ngForm">

            <div class="form-group">
                <label for="firstName">First Name</label>
                <input ngModel required type="text" name="firstName" id="fname">
            </div>

            <div class="form-group">
                <label for="lastName">Last Name</label>
                <input ngModel required type="text" name="lastName" id="lastName">
            </div>

            <div class="form-group">
                <label for="email">Email</label>
                <input ngModel required type="email" name="email" id="email">
            </div>

            <div class="form-group">
                <label for="password">Password</label>
                <input ngModel required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}" type="password" name="password" id="password">
            </div>

            <div class="form-group">
                <label for="verifyPassword">Confirm Password</label>
                <input ngModel type="verifyPassword" name="verifyPassword" id="verifyPassword">
            </div>

            <div class="form-group">
                <label for="birthdate">Birthdate</label> {{maxDate}}
                <input [max]="maxDate" (change)="dateChange($event.target.value)" type="date" name="birthdate" id="birthdate">
            </div>

            <div class="form-group">
                <label for="flatPurchaceDate">Flat Purchace Date</label>
                <input max="2017-04-01" type="date" name="flatPurchaceDate" id="flatPurchaceDate">
            </div>

            <div class="form-group">
                <label for="proficePicture">Profile Picture (URL)</label>
                <input type="text" name="profilePicture" id="profilePicture" placeholder="URL">
            </div>

            <div class="form-group">
                <label for="flatBlock">Flat Block</label>
                <select id="flatBlock" name="flatBlock">
          <option value="A">A</option>
          <option value="B">B</option>
        </select>
            </div>

            <div class="form-group">
                <label for="flatNumber">Flat Number</label>
                <input min="1" max="10" type="number" name="flatNumber" id="flatNumber" placeholder="URL">
            </div>

            <div class="form-group">
                <label for="mobileNumber">Mobile Number</label>
                <input pattern="[1-9]{1}[0-9]{11}" type="tel" name="mobileNumber" id="mobileNumber">
            </div>

            <div class="form-group">
                <label for="subscribeNews">Terms and Conditions</label>
                <input required type="checkbox"  name="terms">
            </div>

            <button  class="btn btn-primary btn-sm">Sign Up</button>
        </form>
    </div>
</div>
还这个 2018年6月28日星期四12:11:34 GMT+0530(IST)

        <h1>{{date}}</h1>

        <form (ngSubmit)="onSignUp(f)" #f="ngForm">

            <div class="form-group">
                <label for="firstName">First Name</label>
                <input ngModel required type="text" name="firstName" id="fname">
            </div>

            <div class="form-group">
                <label for="lastName">Last Name</label>
                <input ngModel required type="text" name="lastName" id="lastName">
            </div>

            <div class="form-group">
                <label for="email">Email</label>
                <input ngModel required type="email" name="email" id="email">
            </div>

            <div class="form-group">
                <label for="password">Password</label>
                <input ngModel required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}" type="password" name="password" id="password">
            </div>

            <div class="form-group">
                <label for="verifyPassword">Confirm Password</label>
                <input ngModel type="verifyPassword" name="verifyPassword" id="verifyPassword">
            </div>

            <div class="form-group">
                <label for="birthdate">Birthdate</label> {{maxDate}}
                <input [max]="maxDate" (change)="dateChange($event.target.value)" type="date" name="birthdate" id="birthdate">
            </div>

            <div class="form-group">
                <label for="flatPurchaceDate">Flat Purchace Date</label>
                <input max="2017-04-01" type="date" name="flatPurchaceDate" id="flatPurchaceDate">
            </div>

            <div class="form-group">
                <label for="proficePicture">Profile Picture (URL)</label>
                <input type="text" name="profilePicture" id="profilePicture" placeholder="URL">
            </div>

            <div class="form-group">
                <label for="flatBlock">Flat Block</label>
                <select id="flatBlock" name="flatBlock">
          <option value="A">A</option>
          <option value="B">B</option>
        </select>
            </div>

            <div class="form-group">
                <label for="flatNumber">Flat Number</label>
                <input min="1" max="10" type="number" name="flatNumber" id="flatNumber" placeholder="URL">
            </div>

            <div class="form-group">
                <label for="mobileNumber">Mobile Number</label>
                <input pattern="[1-9]{1}[0-9]{11}" type="tel" name="mobileNumber" id="mobileNumber">
            </div>

            <div class="form-group">
                <label for="subscribeNews">Terms and Conditions</label>
                <input required type="checkbox"  name="terms">
            </div>

            <button  class="btn btn-primary btn-sm">Sign Up</button>
        </form>
    </div>
</div>
我是否可以通过将返回的日期格式化为与验证器的预期输入相匹配的方式来完成这项工作

        <h1>{{date}}</h1>

        <form (ngSubmit)="onSignUp(f)" #f="ngForm">

            <div class="form-group">
                <label for="firstName">First Name</label>
                <input ngModel required type="text" name="firstName" id="fname">
            </div>

            <div class="form-group">
                <label for="lastName">Last Name</label>
                <input ngModel required type="text" name="lastName" id="lastName">
            </div>

            <div class="form-group">
                <label for="email">Email</label>
                <input ngModel required type="email" name="email" id="email">
            </div>

            <div class="form-group">
                <label for="password">Password</label>
                <input ngModel required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}" type="password" name="password" id="password">
            </div>

            <div class="form-group">
                <label for="verifyPassword">Confirm Password</label>
                <input ngModel type="verifyPassword" name="verifyPassword" id="verifyPassword">
            </div>

            <div class="form-group">
                <label for="birthdate">Birthdate</label> {{maxDate}}
                <input [max]="maxDate" (change)="dateChange($event.target.value)" type="date" name="birthdate" id="birthdate">
            </div>

            <div class="form-group">
                <label for="flatPurchaceDate">Flat Purchace Date</label>
                <input max="2017-04-01" type="date" name="flatPurchaceDate" id="flatPurchaceDate">
            </div>

            <div class="form-group">
                <label for="proficePicture">Profile Picture (URL)</label>
                <input type="text" name="profilePicture" id="profilePicture" placeholder="URL">
            </div>

            <div class="form-group">
                <label for="flatBlock">Flat Block</label>
                <select id="flatBlock" name="flatBlock">
          <option value="A">A</option>
          <option value="B">B</option>
        </select>
            </div>

            <div class="form-group">
                <label for="flatNumber">Flat Number</label>
                <input min="1" max="10" type="number" name="flatNumber" id="flatNumber" placeholder="URL">
            </div>

            <div class="form-group">
                <label for="mobileNumber">Mobile Number</label>
                <input pattern="[1-9]{1}[0-9]{11}" type="tel" name="mobileNumber" id="mobileNumber">
            </div>

            <div class="form-group">
                <label for="subscribeNews">Terms and Conditions</label>
                <input required type="checkbox"  name="terms">
            </div>

            <button  class="btn btn-primary btn-sm">Sign Up</button>
        </form>
    </div>
</div>
编辑 以下是html:

        <h1>{{date}}</h1>

        <form (ngSubmit)="onSignUp(f)" #f="ngForm">

            <div class="form-group">
                <label for="firstName">First Name</label>
                <input ngModel required type="text" name="firstName" id="fname">
            </div>

            <div class="form-group">
                <label for="lastName">Last Name</label>
                <input ngModel required type="text" name="lastName" id="lastName">
            </div>

            <div class="form-group">
                <label for="email">Email</label>
                <input ngModel required type="email" name="email" id="email">
            </div>

            <div class="form-group">
                <label for="password">Password</label>
                <input ngModel required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}" type="password" name="password" id="password">
            </div>

            <div class="form-group">
                <label for="verifyPassword">Confirm Password</label>
                <input ngModel type="verifyPassword" name="verifyPassword" id="verifyPassword">
            </div>

            <div class="form-group">
                <label for="birthdate">Birthdate</label> {{maxDate}}
                <input [max]="maxDate" (change)="dateChange($event.target.value)" type="date" name="birthdate" id="birthdate">
            </div>

            <div class="form-group">
                <label for="flatPurchaceDate">Flat Purchace Date</label>
                <input max="2017-04-01" type="date" name="flatPurchaceDate" id="flatPurchaceDate">
            </div>

            <div class="form-group">
                <label for="proficePicture">Profile Picture (URL)</label>
                <input type="text" name="profilePicture" id="profilePicture" placeholder="URL">
            </div>

            <div class="form-group">
                <label for="flatBlock">Flat Block</label>
                <select id="flatBlock" name="flatBlock">
          <option value="A">A</option>
          <option value="B">B</option>
        </select>
            </div>

            <div class="form-group">
                <label for="flatNumber">Flat Number</label>
                <input min="1" max="10" type="number" name="flatNumber" id="flatNumber" placeholder="URL">
            </div>

            <div class="form-group">
                <label for="mobileNumber">Mobile Number</label>
                <input pattern="[1-9]{1}[0-9]{11}" type="tel" name="mobileNumber" id="mobileNumber">
            </div>

            <div class="form-group">
                <label for="subscribeNews">Terms and Conditions</label>
                <input required type="checkbox"  name="terms">
            </div>

            <button  class="btn btn-primary btn-sm">Sign Up</button>
        </form>
    </div>
</div>

{{date}}
名字
姓
电子邮件
密码
确认密码
生日
平铺日期
个人资料图片(URL)
平块
A.
B
固定数字
手机号码
条款和条件
注册

        <h1>{{date}}</h1>

        <form (ngSubmit)="onSignUp(f)" #f="ngForm">

            <div class="form-group">
                <label for="firstName">First Name</label>
                <input ngModel required type="text" name="firstName" id="fname">
            </div>

            <div class="form-group">
                <label for="lastName">Last Name</label>
                <input ngModel required type="text" name="lastName" id="lastName">
            </div>

            <div class="form-group">
                <label for="email">Email</label>
                <input ngModel required type="email" name="email" id="email">
            </div>

            <div class="form-group">
                <label for="password">Password</label>
                <input ngModel required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}" type="password" name="password" id="password">
            </div>

            <div class="form-group">
                <label for="verifyPassword">Confirm Password</label>
                <input ngModel type="verifyPassword" name="verifyPassword" id="verifyPassword">
            </div>

            <div class="form-group">
                <label for="birthdate">Birthdate</label> {{maxDate}}
                <input [max]="maxDate" (change)="dateChange($event.target.value)" type="date" name="birthdate" id="birthdate">
            </div>

            <div class="form-group">
                <label for="flatPurchaceDate">Flat Purchace Date</label>
                <input max="2017-04-01" type="date" name="flatPurchaceDate" id="flatPurchaceDate">
            </div>

            <div class="form-group">
                <label for="proficePicture">Profile Picture (URL)</label>
                <input type="text" name="profilePicture" id="profilePicture" placeholder="URL">
            </div>

            <div class="form-group">
                <label for="flatBlock">Flat Block</label>
                <select id="flatBlock" name="flatBlock">
          <option value="A">A</option>
          <option value="B">B</option>
        </select>
            </div>

            <div class="form-group">
                <label for="flatNumber">Flat Number</label>
                <input min="1" max="10" type="number" name="flatNumber" id="flatNumber" placeholder="URL">
            </div>

            <div class="form-group">
                <label for="mobileNumber">Mobile Number</label>
                <input pattern="[1-9]{1}[0-9]{11}" type="tel" name="mobileNumber" id="mobileNumber">
            </div>

            <div class="form-group">
                <label for="subscribeNews">Terms and Conditions</label>
                <input required type="checkbox"  name="terms">
            </div>

            <button  class="btn btn-primary btn-sm">Sign Up</button>
        </form>
    </div>
</div>
在HTML中

        <h1>{{date}}</h1>

        <form (ngSubmit)="onSignUp(f)" #f="ngForm">

            <div class="form-group">
                <label for="firstName">First Name</label>
                <input ngModel required type="text" name="firstName" id="fname">
            </div>

            <div class="form-group">
                <label for="lastName">Last Name</label>
                <input ngModel required type="text" name="lastName" id="lastName">
            </div>

            <div class="form-group">
                <label for="email">Email</label>
                <input ngModel required type="email" name="email" id="email">
            </div>

            <div class="form-group">
                <label for="password">Password</label>
                <input ngModel required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}" type="password" name="password" id="password">
            </div>

            <div class="form-group">
                <label for="verifyPassword">Confirm Password</label>
                <input ngModel type="verifyPassword" name="verifyPassword" id="verifyPassword">
            </div>

            <div class="form-group">
                <label for="birthdate">Birthdate</label> {{maxDate}}
                <input [max]="maxDate" (change)="dateChange($event.target.value)" type="date" name="birthdate" id="birthdate">
            </div>

            <div class="form-group">
                <label for="flatPurchaceDate">Flat Purchace Date</label>
                <input max="2017-04-01" type="date" name="flatPurchaceDate" id="flatPurchaceDate">
            </div>

            <div class="form-group">
                <label for="proficePicture">Profile Picture (URL)</label>
                <input type="text" name="profilePicture" id="profilePicture" placeholder="URL">
            </div>

            <div class="form-group">
                <label for="flatBlock">Flat Block</label>
                <select id="flatBlock" name="flatBlock">
          <option value="A">A</option>
          <option value="B">B</option>
        </select>
            </div>

            <div class="form-group">
                <label for="flatNumber">Flat Number</label>
                <input min="1" max="10" type="number" name="flatNumber" id="flatNumber" placeholder="URL">
            </div>

            <div class="form-group">
                <label for="mobileNumber">Mobile Number</label>
                <input pattern="[1-9]{1}[0-9]{11}" type="tel" name="mobileNumber" id="mobileNumber">
            </div>

            <div class="form-group">
                <label for="subscribeNews">Terms and Conditions</label>
                <input required type="checkbox"  name="terms">
            </div>

            <button  class="btn btn-primary btn-sm">Sign Up</button>
        </form>
    </div>
</div>

你在用日期选择器吗?你用的是被动语态吗?您能显示您的表单吗?我在这里静态添加了“0”。我想你可以很容易地改变它。