无法读取null的属性“模式”

时间:2018-09-20 03:20:34

标签: javascript html angular input

我写了两个输入框并向其中添加pattern属性。但是当我在第一个框中输入内容时,它可以正常工作,但是当我输入第二个输入框时,它会引发很多误解!我不知道代码有什么问题,这是我的错误。

    ERROR TypeError: Cannot read property 'pattern' of null
    at Object.eval [as updateDirectives] (RegisterComponent.html:1)
    at Object.debugUpdateDirectives [as updateDirectives] (core.js?09c9:11062)
    at checkAndUpdateView (core.js?09c9:10459)
    at callViewAction (core.js?09c9:10700)
    at execEmbeddedViewsAction (core.js?09c9:10663)
    at checkAndUpdateView (core.js?09c9:10460)
    at callViewAction (core.js?09c9:10700)
    at execEmbeddedViewsAction (core.js?09c9:10663)
    at checkAndUpdateView (core.js?09c9:10460)
    at callViewAction (core.js?09c9:10700)

ERROR CONTEXT DebugContext_ {view: {…}, nodeIndex: 9, nodeDef: {…}, elDef: {…}, elView: {…}}

这是我的html代码:

<input type="password" class="form-control" id="password" name="password"
     #password="ngModel"  pattern="^[A-z0-9_]+$"
    placeholder="{{'global.form.newpassword.placeholder' | translate}}"
    [(ngModel)]="registerAccount.password" minlength=5 maxlength=30 required>

<input type="password" class="form-control" id="confirmPassword" name="confirmPassword" #confirmPasswordInput="ngModel" pattern="^[A-z0-9_]+$"
placeholder="{{'global.form.confirmpassword.placeholder' | translate}}"
[(ngModel)]="confirmPassword" minlength=5 maxlength=30 required>

1 个答案:

答案 0 :(得分:0)

<input id="password" name="password" class="form-control" type="password" placeholder="{{'global.form.newpassword.placeholder' | translate}}" #password="ngModel" pattern="^[A-z0-9_]+$" [(ngModel)]="registerAccount.password" minlength=5 maxlength=30 required>

<input type="password" class="form-control" id="confirmPassword" name="confirmPassword" #confirmPasswordInput="ngModel" pattern="^[A-z0-9_]+$" placeholder="{{'global.form.confirmpassword.placeholder' | translate}}" [(ngModel)]="confirmPasswordTest" minlength=5 maxlength=30 required>