Angular2:异常“没有 t 的提供者!"创建表单时 [英] Angular2: Exception "No provider for t!" when creating a form
问题描述
<div class="form-group"><input type="text" [(ngModel)]="name" ngControl="name" #n="ngForm" required><div [hidden]="n.valid" class="alert alert-danger">值是必需的
我在使用 alpha.52 时遇到以下(不太有用)错误:
<块引用>例外:没有 t! 的提供者!(t-> t)
Angular 使用 NgForm 在其 ngControl 名称下注册控件.通常,您不必显式添加 NgForm 指令,因为它会自动添加–如果您使用 元素.但是您没有
<form>
元素(顺便说一句,就 Twitter Bootstrap 而言,这是有效的/很好的……但不是 Angular).因此,要么将外部
:
或者添加 NgForm 指令:
<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)
解决方案 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">
这篇关于Angular2:异常“没有 t 的提供者!"创建表单时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文