Mark Rajcok
Mark Rajcok

Reputation: 364697

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

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

Upvotes: 4

Views: 5332

Answers (1)

Mark Rajcok
Mark Rajcok

Reputation: 364697

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

Upvotes: 4

Related Questions