Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 无法读取属性';错误';角2中未定义的_Html_Angular - Fatal编程技术网

Html 无法读取属性';错误';角2中未定义的

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">

我正在使用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">     
      <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我无法在这里发布完整的注释,所以我回答了帖子。