使用相同的服务属性填充文本区域-角度

时间:2018-11-29 12:05:03

标签: angular typescript formgroups

我正在使用ngFor在组件的属性之间循环,所以我得到了一系列单选按钮 填充服务(下面将使用genericForm项进行描述)。 仍然在上面定义的同一服务中,我有一个名为“ itemText”的属性, 此属性必须显示在ngFor中的单选按钮下。

登陆组件渲染时,我发现此属性设置为“ undefined”。 但是,当我编译“ itemText”时,它会被填充

我想了解的是: -类似于在加载组件时使呈现为空 -如何使用相同的值填充文本区域

下面是我的代码的结构

谢谢

//service
 this.genericForm = this._fb.group({
  items: this._fb.group({
    item: ['', [Validators.required]], 
    itemText: ['']
  })
});


//component.components.ts
ngOnInit() {

this.AsimpleForm = this.service.genericForm.get('items');     };

 //component.component.html
 <mat-accordion [formGroup]="AsimpleForm" class="form-group">
    <mat-radio-group class="example-radio-group" formControlName="item">
      <mat-expansion-panel *ngFor="let object of objects;">
        <mat-expansion-panel-header>
          <mat-radio-button class="example-radio-button" [value]="object.name">
           {{object.name}}
          </mat-radio-button>
        </mat-expansion-panel-header>
        <textarea formControlName="itemText" [value]="<!-- how to access current itemText here? -->">{{<!-- how to access current itemText value here? -->}}</textarea>
    <span>Facoltativo</span>                     
  </mat-expansion-panel>
</mat-radio-group>

0 个答案:

没有答案