出现错误TypeError:无法读取角度模板驱动形式的undefined属性'value'

时间:2018-07-12 19:24:48

标签: angular angular4-forms

组件html:

 <form novalidate #composeMsgForm="ngForm">
   <div class="form-group">
            <span class="cmpsMsgsub">
              <input name="subject" required maxlength='128' #subject = "ngModel"  [ngModel] = "msgSubject" placeholder="Subject" id='subject' class="subjectInput searchTerm">
            </span>
          </div>
          <div *ngIf="subject.invalid && (subject.dirty || subject.touched)" class="error">
              <div [hidden]="!subject.errors.required">
                  Subject is required!
              </div>
              <div [hidden]="!subject.errors.maxlength">
                  Subject cannot be more than 128 characters long.
              </div>
          </div>
</form>

在component.ts中,我添加了:

import { FormsModule } from '@angular/forms';
declare let jQuery: any;
@Component({
  selector: "app-user",
  templateUrl: "./app-user.component.html",
  styleUrls: ["./app-user.component.css"]
})
export class UserComponent implements OnInit, OnDestroy {
}

我在控制台中遇到错误:

  

core.es5.js:1020错误TypeError:无法读取以下属性的“值”   未定义       在Object.eval [作为updateRenderer](UserComponent.ngfactory.js:701)       在Object.updateRenderer(core.es5.js:12720)       在checkAndUpdateView(core.es5.js:12256)       在callViewAction(core.es5.js:12599)       在execComponentViewsAction(core.es5.js:12531)       在checkAndUpdateView(core.es5.js:12257)       在callViewAction(core.es5.js:12599)       在execComponentViewsAction(core.es5.js:12531)       在checkAndUpdateView(core.es5.js:12257)       在callViewAction(core.es5.js:12599)

我不明白自己做错了什么。 我已关注tutplus angular4 template driven form 我正在使用角度4 +

0 个答案:

没有答案