Html 无法读取属性';错误';角2中未定义的
我正在使用angular2验证我的模板,但同时显示此错误:Html 无法读取属性';错误';角2中未定义的,html,angular,Html,Angular,我正在使用angular2验证我的模板,但同时显示此错误: Cannot read the property 'errors' of undefined. 这是我的模板: <h3 class = "head">{{title}}</h3> <form [ngFormModel]="form" #f="ngForm"> <div class="row"> <div class="form-group">
Cannot read the property 'errors' of undefined.
这是我的模板:
<h3 class = "head">{{title}}</h3>
<form [ngFormModel]="form" #f="ngForm">
<div class="row">
<div class="form-group">
<label class="formHeading">Facebook</label>
<input type="text" id="facebook" class="form-control col-xs-3" ngControl="facebook" #facebook="ngForm" >
</div>
<div *ngIf ="facebook.touched && facebok.errors">
<div class="form-row btn">
<button type="submit" class="btn btn-primary pull-right butspace" [disabled]="!f.valid">Save</button>
</div>
</div>
</form>
{{title}
脸谱网
拯救
我不知道它为什么会显示这个错误。有人能修复它吗?首先,您在错误属性上使用了
facebook
而不是facebook
如果这还不能解决问题,您可能在分配前使用了facebook
对象,例如,如果它是@Input()
,就会发生这种情况
使用Elvis操作员
:
*ngIf ="facebook?.touched && facebook?.errors"
埃尔维斯接线员为我工作。我正在构造函数中设置表单组,这显然对DOM来说太晚了。@hholtij我无法在这里发布完整的注释,所以我回答了帖子。