
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
ngx-signal-pagination
Advanced tools
Pagination for Angular, powered by signals 🚦
RouterModule
for this as it uses RxJSlet-...
are currently of type any
.
<ng-template
#paginationTemplate
let-currentPage="currentPage"
this.todoDal
.getAll(this.pageChanges() ?? this.simpleQueryStringService.getPageFromQueryString() ?? 1)
.then(res => ({
pagedData: res.todos,
currentPage: res.currentPage,
nrOfPages: res.nrOfPages,
}));
That's currently not clear, the query
parameter now accepts anything defined through injectQuery()
.
query = input.required<CreateQueryResult<T, any>>();
Due to angular-query's type narrowing, it's a bit tricky to customize this.npm install ngx-signal-pagination
First, the TypeScript bits - import the pagination component, define data and define pagination config:
@Component({
selector: 'omg-awesome',
imports: [NgxSignalPaginationComponent],
templateUrl: './awesome.component.html',
})
export class AwesomeComponent {
shows = [
{ title: 'Game of Thrones', rating: 9.5 },
{ title: 'Black Mirror', rating: 9.5 },
/* ... */
];
paging: PaginationOptions = { nrOfItemsPerPage: 5 };
}
Then you can either use the default template:
<ngx-signal-pagination [data]="shows" [config]="paging" #pagination />
<ul class="list-[square] ml-4">
@for (show of pagination.pageData(); track show.title) {
<li>{{ show.title }} gets a {{ show.rating }}</li>
}
</ul>
Alternatively, you can roll your own template:
<ngx-signal-pagination [data]="shows" [config]="paging" #paginationCustomTemplate>
<ng-template
#paginationTemplate
let-currentPage="currentPage"
let-pages="pages"
let-previous="previous"
let-next="next"
let-goTo="goTo"
>
<ol class="flex">
<li class="p-3" (click)="previous()">previous</li>
@for (page of pages(); track page) {
<li class="p-3 border-solid border-amber-300 border-b-2" [class.bg-amber-300]="page === currentPage()" (click)="goTo(page)">
{{ page }}
</li>
}
<li class="p-3" (click)="next()">next</li>
</ol>
</ng-template>
</ngx-signal-pagination>
<ul class="list-[square] ml-4">
@for (show of paginationCustomTemplate.pageData(); track show.title) {
<li>{{ show.title }} gets a {{ show.rating }}</li>
}
</ul>
Asynchronous data retrieval works using the @tanstack/angular-query-experimental library. You'll need to define your query, as well as do a bit of page change handling*.
*I've tried exposing a signal from the pagination component, but this signal not always being there due to the rendering lifecycle made this approach quite cumbersome.
First, the TypeScript bits - import the async pagination component, define your and define pagination config:
@Component({
selector: 'omg-awesome',
imports: [NgxSignalPaginationAsyncComponent],
templateUrl: './awesome.component.html',
})
export class AwesomeComponent {
private todoDal = inject(TodoDal);
private simpleQueryStringService = inject(SimpleQueryStringService);
paging: PaginationOptions = { nrOfItemsPerPage: 5 };
pageChanges = signal<number | null>(null);
todoQuery = injectQuery(() => ({
queryKey: ['todos', this.pageChanges() ?? this.simpleQueryStringService.getPageFromQueryString() ?? 1],
queryFn: () => this.todoDal.getTodos(this.pageChanges() ?? this.simpleQueryStringService.getPageFromQueryString() ?? 1),
placeholderData: prev => prev,
}));
goToPage(p: number) {
this.pageChanges.set(p);
}
}
In this scenario, my TodoDal
looks like this:
@Injectable({ providedIn: 'root' })
export class TodoDal {
#todos = [
'#1 Clean the house',
'#2 Eat food',
'#3 Exercise',
/* ... */
];
getTodos(page: number): Promise<{ pagedData: any[], currentPage: number; nrOfPages: number; }> {
return new Promise(resolve => {
setTimeout(() => {
resolve({
pagedData: this.#todos.slice((page - 1) * 5, page * 5),
currentPage: page,
nrOfPages: Math.ceil(this.#todos.length / 5),
});
}, 2000);
});
}
}
Then you can either use the default template:
<ngx-signal-async-pagination [query]="todoQuery" (pageChange)="goToPage($event)" [config]="paging" #asyncPagination />
<ul class="list-[square] ml-4">
@for (todo of asyncPagination.pageData(); track todo) {
<li>{{ todo }}</li>
}
</ul>
Or roll a custom template as with the in-memory variant.
FAQs
Pagination for Angular, powered by signals 🚦
The npm package ngx-signal-pagination receives a total of 15 weekly downloads. As such, ngx-signal-pagination popularity was classified as not popular.
We found that ngx-signal-pagination demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.