本文介绍了使用ngControl导致的错误:没有ControlContainer的提供程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在我的应用程序中首次使用ngControl:
I'm trying to use ngControl for the first time in my app:
<md-input placeholder="Amount" value="0" ngControl="ammount" required></md-input>
在我的组件中添加了以下内容:
Added the following in my component:
import { FORM_PROVIDERS,FORM_DIRECTIVES } from '@angular/common';
..
directives: [MD_INPUT_DIRECTIVES,
FORM_DIRECTIVES,
],
providers: [FORM_PROVIDERS],
我得到这个错误:
browser_adapter.ts:78 EXCEPTION: Error: Uncaught (in promise): Template parse errors:
No provider for ControlContainer ("
[ERROR ->]<md-input placeholder="Amount" value="0" ngControl="ammount" required></md-input>
我想念什么?
推荐答案
我认为您忘记了将md-input
组件包装在form
标记中,否则ngControl
无效:
I think that you forgot to wrap the md-input
component in form
tag, otherwise ngControl
won't work:
<form>
...
<md-input placeholder="Amount" value="0" ngControl="ammount" required></md-input>
...
</form>
这篇关于使用ngControl导致的错误:没有ControlContainer的提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!