我尝试验证Angular2中的输入时出错

时间:2017-05-30 17:08:05

标签: html angular validation typescript angular-validation

我正在尝试验证输入

    <md-input-container class="name-input">
                <input type="text" mdInput [(ngModel)]="tileName"  #tileNameInput="ngModel" 
                      id="tileNameInput" name="tileNameInput" 
                      required placeholder="{{ 'Name' | translate }}"/>
                <md-error *ngIf="v.errors.required">Tile Name is required</md-error>
            </md-input-container>

我收到了错误:

  

错误类型错误:无法读取未定义的属性“错误”           在Object.eval [as updateDirectives](HeaderComponent.html:104)           at Object.debugUpdateDirectives [as updateDirectives](core.es5.js:12784)           在checkAndUpdateView(core.es5.js:12122)           在callViewAction(core.es5.js:12485)           at execEmbeddedViewsAction(core.es5.js:12443)           在checkAndUpdateView(core.es5.js:12123)           在callViewAction(core.es5.js:12485)           在execComponentViewsAction(core.es5.js:12417)           在checkAndUpdateView(core.es5.js:12128)           在callViewAction(core.es5.js:12485)

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

使用输入字段的名称而不是v,例如:*ngIf="tileNameInput.errors.required"