diff options
Diffstat (limited to 'ufund-ui/src/app/components/need-list/need-list.component.ts')
-rw-r--r-- | ufund-ui/src/app/components/need-list/need-list.component.ts | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/ufund-ui/src/app/components/need-list/need-list.component.ts b/ufund-ui/src/app/components/need-list/need-list.component.ts index d637005..d027690 100644 --- a/ufund-ui/src/app/components/need-list/need-list.component.ts +++ b/ufund-ui/src/app/components/need-list/need-list.component.ts @@ -1,6 +1,6 @@ -import {Component, Input, OnInit} from '@angular/core'; +import {Component, Input, OnChanges, OnInit} from '@angular/core'; import {Need} from '../../models/Need'; -import {BehaviorSubject, Observable} from 'rxjs'; +import {Observable} from 'rxjs'; @Component({ selector: 'app-need-list', @@ -8,9 +8,9 @@ import {BehaviorSubject, Observable} from 'rxjs'; templateUrl: './need-list.component.html', styleUrl: './need-list.component.css' }) -export class NeedListComponent implements OnInit { +export class NeedListComponent implements OnChanges { - @Input({required: true}) needs!: Observable<Need[]> + @Input({required: true}) needs!: Need[] visibleNeeds: Need[] = []; currentPage: number = 0; @@ -21,14 +21,8 @@ export class NeedListComponent implements OnInit { ) {} - ngOnInit() { - this.needs.subscribe(needs => { - this.totalPages = Math.ceil(needs.length / this.itemsPerPage); - this.totalPages = Math.ceil(needs.length / this.itemsPerPage); - this.visibleNeeds = needs.slice(this.currentPage * this.itemsPerPage, (this.currentPage + 1) * this.itemsPerPage); - console.log(needs.length) - }) - + ngOnChanges() { + this.updateVisibleNeeds() } decrementPage() { @@ -57,8 +51,8 @@ export class NeedListComponent implements OnInit { } updateVisibleNeeds() { - // this.totalPages = Math.ceil(this.needs.length / this.itemsPerPage); - // this.visibleNeeds = this.needs.slice(this.currentPage * this.itemsPerPage, (this.currentPage + 1) * this.itemsPerPage); + this.totalPages = Math.ceil(this.needs.length / this.itemsPerPage); + this.visibleNeeds = this.needs.slice(this.currentPage * this.itemsPerPage, (this.currentPage + 1) * this.itemsPerPage); } resetVisibleNeeds() { |