Angular2: Exception “No provider for t!” when creating a form

微笑、不失礼 提交于 2020-01-14 12:44:57

问题


<div id="my-form" class="form-inline">
  <div class="form-group">
    <input type="text" [(ngModel)]="name" ngControl="name" #n="ngForm" required>
    <div [hidden]="n.valid" class="alert alert-danger">
      Value is required
    </div>
  </div>
</div>

I get the following (less than helpful) error with alpha.52:

EXCEPTION: No provider for t! (t-> t)


回答1:


Angular registers controls under their ngControl names with the NgForm. Normally, you don't have to add the NgForm directive explicitly because it automatically gets added – if you use a <form> element. But you don't have a <form> element (which BTW is valid/fine as far as Twitter Bootstrap is concerned... but not Angular so much). So, either change the outer <div> to <form>:

<form id="my-form" class="form-inline">

Or add the NgForm directive:

<div ngForm id="my-form" class="form-inline">


来源:https://stackoverflow.com/questions/33768631/angular2-exception-no-provider-for-t-when-creating-a-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!