我一直在这里处理另一个问题,帮助者有点安静,我需要很快找到解决方案。浏览此处获取更多信息
我已经实现了新代码,发现数组正在向浏览器返回“false”:
我已经从 get 请求映射,然后尝试将佣金 $ 绑定到 click-cards.component.html。然后,这应该过滤掉所有重复的记录,并使用 lodash 将它们呈现为组。
编辑:根据反馈,但结果似乎仍然相同
click-cards.component.ts
import { Component, OnInit } from '@angular/core';
import { Commission } from '../commission';
import { AnalyticsService } from '../analytics.service';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import * as _ from 'lodash';
@Component({
selector: 'app-click-cards',
templateUrl: './click-cards.component.html',
styleUrls: ['./click-cards.component.scss']
})
export class ClickCardsComponent implements OnInit {
commissions$: Observable<any>;
constructor(private analyticsService: AnalyticsService) {}
ngOnInit() {
this.getCommissions();
}
getCommissions(){
this.commissions$ = this.analyticsService.getAllCommissionData().pipe(
map((commissions: Commission[]) => {
if (commissions !== undefined && commissions !== null) {
return _.uniqBy(commissions, 'url');
}
}),
map((commissions: Commission[]) => {
commissions = _.groupBy(commissions, commission => commission.page_type);
return commissions;
})
)
}
}
我似乎无法找到让佣金 $ 绑定到 .html 文件的方法:
click-cards.html
<ng-container *ngIf="commissions$ | async as commissions">
<ng-container *ngFor="let page_type of ['home', 'article','statistics', 'products']">
<h4>{{ page_type | titlecase }}</h4>
<p *ngIf="!commissions[page_type]">No {{ page_type }} Commissions Logged Yet</p>
<ul *ngFor="let card of commissions[page_type]">
<app-click-card [card]="card"></app-click-card>
</ul>
</ng-container>
</ng-container>
有谁知道我在这里做错了什么?我通常不使用 Observables,所以我通常订阅服务 REST 方法并且它可以工作。所以我对这个过程有点陌生。