Currently, I am facing a challenge in my Angular 10.1.0 project while attempting to implement pagination by slicing my data array. The issue arises with the error message
TS2339: Property 'slice' does not exist on type 'WritableSignal<Data[]>'
.
Here's a snippet from my component:
export class Component implements OnInit {
data = signal<Data[]>([]);
currentPage: number = 1;
constructor(private httoService: HttpService) {}
ngOnInit(): void {
this.fetchData();
}
fetchData(): void {
this.httpService.getData().subscribe((data) => {
this.data.set(data);
});
}
get paginatedData() {
const start = (this.currentPage - 1) * 100;
const end = start + 100;
return this.data.slice(start, end);
}
...
}
Details of my http.service.ts file:
export class HttpService {
http = inject(HttpClient);
private apiUrl = 'url'
getProducts(): Observable<Data[]> {
return this.http.get<Data[]>(this.apiUrl);
}
}
I have attempted pre-processing the values before applying slice:
const dataArray = Array.from(this.data().values)
but it yielded 0 as the result.