加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – 使用ngControl导致错误:没有ControlContainer的提供

发布时间:2020-12-17 06:50:05 所属栏目:安全 来源:网络整理
导读:我正在尝试在我的应用中第一次使用ngControl: md-input placeholder="Amount" value="0" ngControl="ammount" required/md-input 在我的组件中添加了以下内容: import { FORM_PROVIDERS,FORM_DIRECTIVES } from '@angular/common';..directives: [MD_INPUT
我正在尝试在我的应用中第一次使用ngControl:

<md-input placeholder="Amount" value="0" ngControl="ammount" required></md-input>

在我的组件中添加了以下内容:

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将无法工作:

<form>
   ...
   <md-input placeholder="Amount" value="0" ngControl="ammount" required></md-input>
   ...
</form>

This directive can only be used as a child of NgForm or NgFormModel.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读