角度找不到类型为“对象”的其他支持对象“ [对象对象]”。 NgFor仅支持绑定到可迭代对象,例如数组

时间:2019-05-17 15:42:42

标签: angular

我正在构建一个角度应用程序,该应用程序将通过遍历对象来显示表中的记录。在将其发送到html组件之前,我可以看到该对象具有值。不知道为什么该对象似乎无法打印。

控制台出现错误

  

找不到类型为“对象”的其他支持对象“ [对象对象]”。 NgFor仅支持绑定到数组等Iterable。

父组件

public getTermsDetails() {
        if (this.ManagerStrategyId != null) {
            this.termsService.getTermsDetails(this.ManagerStrategyId).subscribe((data: any) => {
                this.TermDetails = data;
                this.OriginalList = JSON.parse(JSON.stringify(data));
                this.FundClasses = this.TermDetails.FundClassViewModel;
                this.LegalFundClasses = this.TermDetails.LegalFundClassViewModel;

                this.TermDetails.FundClassViewModel.FundDetailsViewModel.forEach(funDetail=> {
                    funDetail.FundClassDetailsViewModel = funDetail.FundClassDetailsViewModel
                        .reduce((prev, next) => prev = prev.concat(next), [])
                        .filter(obj => obj.InvestedAmount !== null);
                });

            });
        }
    }   

父组件HTML

<mgr-legal-fund-classes  [LegalFundClasses]="LegalFundClasses" ></mgr-legal-fund-classes>

子组件

public get LegalFundClasses(): any {
    return this._legalFundClasses;
}
@Input()
public set LegalFundClasses(value: any) {
    this._legalFundClasses = value;
}

子组件html表

<div *ngIf="LegalFundClasses && LegalFundClasses.LegalFundClassDetailsViewModel">


        <table class="fundClassesTable table-striped">

            <tr>
                <th class="tableItem bold">Legal Class Name</th>
                <th class="tableItem bold">Last Edited</th>
                <th class="tableItem bold">Legal Class ID</th>
                <th class="tableItem bold"></th>
                <th class="tableItem bold">TERMS</th>

            </tr>

            <ng-container *ngFor="let fundClass of LegalFundClasses.LegalFundClassViewModel">
                <tr *ngFor="let f of fundClass['LegalFundClassDetailsViewModel'] | keyvalue">
                    <td class="tableItem">{{f.value.Description}}</td>
                    <td class="tableItem"></td>
                    <td class="tableItem">{{f.value.Id}}</td>
                    <td class="tableItem"></td>
                    <td class="tableItem"></td>

                </tr>
            </ng-container>
        </table>
    </div>

JSON-LegalFundClassViewModel

    {
  "LegalFundClassDetailsViewModel": [
    {
      "Description": "Class B",
      "AuditSummary": null,
      "FeesReviewSummary": "dmukerji Mar 11, 2019",
      "TermsReviewSummary": "rmenon May 14, 2019",
      "Id": 13717,
      "CurrencyId": null,
      "ManagerStrategyId": null,
      "SubVotingId": null,
      "SubHotIssueId": null,
      "RedsFrqncyId": 5,
      "RedsNoticeDays": 46,
      "NoticeTypeOfDaysId": 2,
      "LockupTypeId": 5,
      "HardDurationMonthsId": null,
      "SoftDurationMonthsId": null,
      "LockupFees0To12Pct": 0,
      "LockupFees12To24Pct": 0,
      "LockupFees24To36Pct": 0,
      "WebfolioRedsFee": null,
      "LockupComments": "In the SOT, there is a 1-year lock, this is no longer applicable and was only applicable for the original transfer from Sylebra commingled.",
      "ApplyGateDecliningBalance": false,
      "GateInvestorPct": 0,
      "GateSourceId": null,
      "GateFundClassPct": 0,
      "IntialProceeds": 100,
      "PaymentInDays": 30,
      "PaymentTypeOfDaysId": 2,
      "HoldbackPercentage": 0,
      "HoldbackPayment": null,
      "HoldbackTypeOfDaysId": null,
      "ManagementFeeRate": 0,
      "IncentiveFeeRate": 30,
      "IncentiveRealizationFrequencyId": 7,
      "HighWaterMarkId": 1,
      "HurdleRate": false,
      "HurdleRateBasisId": null,
      "HurdleRatePct": null,
      "HurdleRateIndexId": null,
      "PreferredReturnRatePct": 0,
      "GpCatchUp": null,
      "PreferredReturnComments": null,
      "Clawback": false,
      "ClawbackPercentage": null,
      "AssetFeeDiscountTypeId": 1,
      "FeeComments": "New fees effective 1/1/2019 \n\nManagement fee is an Asset Based fee of the lesser of $1M or 1.5% of NAV.  This is a payment in advance of any performance fee, making the management fee effectively zero.\n\nIncentive fee is 30% on first 15% of performance, 35% thereafter.\n\nAudit holdbacks should be zero unless the vehicle is in liquidation, in which case it's typically a 5% holdback paid once the audit is completed where applicable or 2-3 months after the final NAV once all the expenses have been paid.",
      "FeeReductionsNegotiated": null,
      "InvestmentStatusId": 1
    },
    {
      "Description": "Class A",
      "AuditSummary": null,
      "FeesReviewSummary": "rmenon May 14, 2019",
      "TermsReviewSummary": "rmenon May 14, 2019",
      "Id": 13713,
      "CurrencyId": null,
      "ManagerStrategyId": null,
      "SubVotingId": null,
      "SubHotIssueId": null,
      "RedsFrqncyId": 5,
      "RedsNoticeDays": 46,
      "NoticeTypeOfDaysId": 2,
      "LockupTypeId": 5,
      "HardDurationMonthsId": null,
      "SoftDurationMonthsId": null,
      "LockupFees0To12Pct": 0,
      "LockupFees12To24Pct": 0,
      "LockupFees24To36Pct": 0,
      "WebfolioRedsFee": null,
      "LockupComments": "In the SOT, there is a 1-year lock, this is no longer applicable and was only applicable for the original transfer from Sylebra commingled.",
      "ApplyGateDecliningBalance": false,
      "GateInvestorPct": 0,
      "GateSourceId": null,
      "GateFundClassPct": 0,
      "IntialProceeds": 100,
      "PaymentInDays": 30,
      "PaymentTypeOfDaysId": 2,
      "HoldbackPercentage": 0,
      "HoldbackPayment": null,
      "HoldbackTypeOfDaysId": null,
      "ManagementFeeRate": 0,
      "IncentiveFeeRate": 30,
      "IncentiveRealizationFrequencyId": 7,
      "HighWaterMarkId": 1,
      "HurdleRate": false,
      "HurdleRateBasisId": null,
      "HurdleRatePct": null,
      "HurdleRateIndexId": null,
      "PreferredReturnRatePct": 0,
      "GpCatchUp": null,
      "PreferredReturnComments": null,
      "Clawback": false,
      "ClawbackPercentage": null,
      "AssetFeeDiscountTypeId": 1,
      "FeeComments": "New fees effective 1/1/2019 \n\nManagement fee is an Asset Based fee of the lesser of $1M or 1.5% of NAV.  This is a payment in advance of any performance fee, making the management fee effectively zero.\n\nIncentive fee is 30% on first 15% of performance, 35% thereafter.\n\nAudit holdbacks should be zero unless the vehicle is in liquidation, in which case it's typically a 5% holdback paid once the audit is completed where applicable or 2-3 months after the final NAV once all the expenses have been paid.",
      "FeeReductionsNegotiated": null,
      "InvestmentStatusId": 1
    }
  ]
}

1 个答案:

答案 0 :(得分:0)

查看了r json个数据后,我认为问题出在以下代码行:

 <ng-container *ngFor="let fundClass of LegalFundClasses.LegalFundClassViewModel">
       <tr *ngFor="let f of fundClass['LegalFundClassDetailsViewModel'] | keyvalue">

尝试以下代码:

<ng-container *ngFor="let fundClass of LegalFundClasses.LegalFundClassViewModel">
            <tr>
                <td class="tableItem">{{fundClass .Description}}</td>
                <td class="tableItem"></td>
                <td class="tableItem">{{fundClass.Id}}</td>
                <td class="tableItem"></td>
                <td class="tableItem"></td>

            </tr>
</ng-container>

LegalFundClassDetailsViewModel内没有任何名为LegalFundClasses.LegalFundClassViewModel的对象,这就是为什么您会出错的原因。