【问题标题】:Angular 2 component as attributeAngular 2 组件作为属性
【发布时间】:2017-07-30 04:06:04
【问题描述】:

我想知道:如何将模板中选择器使用的组件的值与模型中声明的对象绑定?

FormComponent 具有选择器“interface-form”。

代码如下:

@Component({
  moduleId: 'module.id',
  selector: 'create-interface',
  template: '    
<div class="content" style="margin : 20px;">
  <div class="header-section row">
    <button class="btn"> < Retour</button>
  </div>
  <interface-form [data]="data" [dataFields]="this.form.dataFields">
  </interface-form>
</div>'
})

export class CreateComponent {

  public form: FormComponent;
  ...

我希望我的表单属性是我的模板中声明的接口表单的实例,所以如果我这样做:

this.form.addField(...),我的模板会动态变化。

【问题讨论】:

标签: angular


【解决方案1】:

我认为您正在寻找的是FormArray。看看吧:

https://angular.io/docs/ts/latest/api/forms/index/FormArray-class.html

【讨论】:

    猜你喜欢
    • 2018-03-01
    • 2018-02-13
    • 1970-01-01
    • 1970-01-01
    • 2016-07-04
    • 2017-05-20
    • 2016-07-21
    • 1970-01-01
    • 2019-01-18
    相关资源
    最近更新 更多