// шаблон
<div *ngFor="let user of reportsWithUser$|async">
{{user.name}}
</div>
//компонент
import {Observable} from "rxjs";
import {map, switchMap} from "rxjs/operators";
import * as _ from 'underscore';
interface User {
user_id: number;
name: string;
date: string;
}
interface Report {
report_date: string;
users_id: number;
}
interface UserWithReports extends User {
reports: Report[];
reportWithMaxDate: Report;
}
export function assignReportToUser(user: User, reports: Report[]): UserWithReports {
const repFiltered = reports.filter(report => report.report_date >= user.date);
return {...user, reports: repFiltered.filter(report => report.users_id === user.user_id), reportWithMaxDate: _.max(repFiltered, (r) => r.report_date)};
}
export class AnyComponent {
reportsWithUser$: Observable<UserWithReports[]>;
constructor(
public reportsService: any,
public usersService: any
) {
this.reportsWithUser$ = this.reportsService.fetch().pipe(
switchMap((reports: Report[]) => this.usersService.fetch().pipe(
map((users: User[]) => {
return users.map(user => assignReportToUser(user, reports)).filter((user) => user.reportWithMaxDate !== null);
})
)
)
)
}
}
.menu ul li a {
display: flex;
align-items: center;
}
.menu ul li a img {
flex-shrink: 0;
margin-right: 10px;
}
.menu ul li a img {
align-self: stretch;
}
.menu ul li a {
display: flex;
align-items: baseline;
}
<a routerLink="/"
[queryParams]="{ userId: '123' }">
Users
</a>
<a routerLink="/userId/123"
queryParamsHandling="merge">
Users
</a>
import {Router} from "@angular/router";
@Component()
export class AppComponent implements OnInit {
constructor(
private router: Router
){}
ngOnInit() {
this.router.navigateByUrl("/userId/123");
// или
this.router.navigateByUrl({queryParams: {userId: 123}});
}
}