Не удается связать FormArray с html * ngFor - PullRequest
0 голосов
/ 12 января 2020

Проблема в том, что * ngFor не показывает содержимое моего массива. Бизнес-класс инициализирован и правильно заполнен данными. Все свойства возвращают данные в HTML. Все, что отображается на веб-странице, кроме массива, не привязывается к html. Включить - это изображение содержимого данных, переданное в html.

Main TS class 
......
@Input() businessProfileGroup: FormGroup;

**ngOnInit**()
{
    // Create instance
    this.businessProfileGroup  = 
    this.busProfileCtrl.InitbusinessProfile(this.fb,this.genericServices.getCurrSession.Id);
 }
 // DefaultRates contains an array of 7 items.
 // Called from Html
 **getDefaultRates()**  {      
    return this.busProfileCtrl.getDefaultRates() as FormArray;          
 } 

 // Example of a function that works fine. Called from html
 **ImportGuid ()**
 {
    return this.businessProfileGroup.get('ImportGuid').value;
 }

// class busProfileCtrl.ts
// Definition of _businessProfileGroup
**InitbusinessProfile**(fb: FormBuilder,sessionId: string) : FormGroup {  
    this._sessionId = sessionId;
    this._businessProfileGroup =   fb.group({
        Id:                 [-1,Validators.required],
        SessionId:          [sessionId],
        TypeOfIndustryCode: [-1,Validators.required],
        ...... many more properties .....
        TypeOfBilling:      [-1,Validators.required],
        MethodCalcExchRate: [-1,Validators.required],
        DefaultRates:       fb.array([])
});
// populate _businessProfileGroup
**SetbusinessProfile** (resp: businessProfile ) : FormGroup {  
    for (const c in this._businessProfileGroup.controls) {
        let value = resp[c];
        if (c == 'DefaultRates')
        {
            let formGroupArray = this._businessProfileGroup.controls['DefaultRates'] as FormArray;
            for(var i = 0; i < value.length; i++ )
            {
                let formatedItem = <FormArray>value[i];
                formGroupArray.controls.push(formatedItem);
            }
        } else {
            this._businessProfileGroup.controls[c].setValue(value);
        }         
    }
    return this._businessProfileGroup;     
}   
**getDefaultRates()** {
    return  this._businessProfileGroup.get('DefaultRates') as FormArray;
}

<form [formGroup]="businessProfileGroup">
 ...........
<div class="col-6 left-alignSN"  >
        <table style="width:100%;text-align: center;">
           <thead>
                <th style="width:30%">{{getLabel(39, 'Currency')}}</th>
                <th style="width:70%">{{getLabel(181,'Exchange Rate')}}</th> 
           </thead>
           <tbody ***ngFor**="let rowItem of getDefaultRates.controls" >
                <tr>
                    <td><input type='text' [value]='rowItem.CurrencyCode'/></td>  
                    <td><input type='text' [value]='rowItem.ConversionRate'/></td>  
                </tr>
           </tbody>       
        </table> 
</div>   
  ....................
</form>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...