Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度嵌套异步NGF_Angular_Typescript - Fatal编程技术网

Angular 角度嵌套异步NGF

Angular 角度嵌套异步NGF,angular,typescript,Angular,Typescript,我目前正在用angular开发一个应用程序。我在*ngFor模板指令中遇到了一个非常奇怪的问题: <div *ngfor="let accountGroup of groupedAccountsList"> <h3 class="accounts__identifier"> {{accountGroup.key}} </h3> <table class="datalist"> <tr c

我目前正在用angular开发一个应用程序。我在
*ngFor
模板指令中遇到了一个非常奇怪的问题:

<div *ngfor="let accountGroup of groupedAccountsList">
    <h3 class="accounts__identifier">
        {{accountGroup.key}}
    </h3>
    <table class="datalist">
        <tr class="datalist__header">
            <th class="datalist__column">
                {{ 'accounts.number' | translate }}
            </th>
        </tr>
        <tr *ngfor="let account of accountGroup.accounts" class="datalist__row">
            <td class="datalist__column">
                {{account.accountNumber}}
            </td>
        </tr>
    </table>
</div>
所有分组都必须由自定义同步代码完成。必须做到以下几点(IMO)

this.groupedAccountsList=this.resourceService
.getAccounts(data.client.id)
.flatMap(o=>从(o)可以观察到)
.groupBy(o=>o.relationship.id)
.map(o=>{
返回{
钥匙:o.key,
账目:o.toArray()
};
})
.toArray()
我对可观察对象和RxJS的理解是否存在一般性错误,或者嵌套的异步管道是否不起作用


干杯

在您的代码示例中,我没有看到任何使用
async
管道的情况
Observable.prototype.groupBy无疑是一个优雅的解决方案(顺便说一句,不需要指定类型参数)
this.resourceService
    .getAccounts(data.client.id)
    .subscribe(accounts => {
        let hash = {};
        for (let acc of accounts) {
            if (!hash[acc.relationship.id]) {
                hash[acc.relationship.id] = [];
            }
            hash[acc.relationship.id].push(acc);
        }
        this.groupedAccountsList = Object.keys(hash).map(key => {
            return {
                key,
                accounts: hash[key]
            };
        });
    });
this.groupedAccountsList = this.resourceService
    .getAccounts(data.client.id)
    .flatMap<AccountModel>(o => Observable.from(o))
    .groupBy<string, AccountModel>(o => o.relationship.id)
    .map(o => {
         return {
             key: o.key,
             accounts: o.toArray()
        };
    })
    .toArray()