微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

angular – 当子组件具有ngModelGroup时,没有ControlContainer的提供者

我似乎无法弄清楚这一点,它根本不起作用.

这是原始的plunker,由Pascal Prekht编写,这是对模板驱动形式的解释:

here是我的fork,它是完全相同的东西,除了我试图加载其中一个字段集作为一个单独的子组件.

这是代码

@Component({
  selector:'form-group-component',template:`
    <fieldset ngModelGroup="anotherAddress">
      <div>
        <label>Street2:</label>
        <input type="text" name="street2" ngModel>
      </div>

    </fieldset>

  `
})
export class FormGroupComponent{

}

@Component({
  selector: 'form-component',directives:[FormGroupComponent],template: `
    <form #form="ngForm">

      <form-group-component></form-group-component>  

      <fieldset ngModelGroup="address">
        <div>
          <label>Street:</label>
          <input type="text" name="street" ngModel>
        </div>
        <div>
          <label>Zip:</label>
          <input type="text" name="zip" ngModel>
        </div>
        <div>
          <label>City:</label>
          <input type="text" name="city" ngModel>
        </div>
      </fieldset>

    </form>
  `
})
export class FormComponent {


}

因此,在切割其中一个feildset并将其加载到单独的指令中之后,它将不再起作用!

有几个封闭的问题,但没有它们正在发挥作用.

This
This

我知道这是一个老问题.但是将来有人可能会发现它很有用.我有同样的问题,看起来当组件有< form>时出现错误没有formGroup指令的标签,模块正在导入 ReactiveFormModule.因此,要解决此问题,请确保所有< form>标签有formGroup指令,如果它们的模块正在导入ReactiveFormModule.

原文地址:https://www.jb51.cc/angularjs/142196.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐