(Please help, still not resolved)So I am following this stackoverflow(with mat-card) and this(with observable) in combination to try to solve my problem.
I have an observable of an array of objects, and I want to use *ngFor
along with mat-card
to display them, and then there's a paginator at the very bottom of the page.
Right now, The observables are linked up properly(because it's displaying), but the paginator doesn't seem to show anything(pic), wondering if anyone could help, thank you so much!
(There's a lot of code for other functionalities, so I will try my best to only list out the ones we need, if you feel like there's anything missing please let me know)
HTML:
<div *ngIf="obs| async as objects>
<div>
<div>
<mat-card *ngFor="let ob of objects"> ... </mat-card>
</div>
<mat-paginator
[showFirstLastButtons]="true"
[pageSizeOptions]="[10, 20, 50, 100]">
</mat-paginator>
</div>
TS:
Side note: filtered$
is the original observable of array I used for the mat-card
, now I'm adding paginator, so in HTML you can see I changed to obs
public dataSource = new MatTableDataSource();
@ViewChild(MatPaginator) paginator: MatPaginator;
obs: Observable<any>;
public filtered$: Observable<Array<An Object>>;
constructor(private changeDetectorRef: ChangeDetectorRef){};
ngOnInit(){
...;
this.filtered$
.pipe(takeUntil(...))
.subscribe((arr) => (this.dataSource.data = arr));
this.changeDetectorRef.detectChanges();
this.dataSource.paginator = this.paginator;
this.obs = this.dataSource.connect();
}