Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, DebugElement, TemplateRef, ViewChild } from '@angular/core';
import { Component, DebugElement, Signal, TemplateRef, viewChild } from '@angular/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { By } from '@angular/platform-browser';

Expand Down Expand Up @@ -254,7 +254,7 @@ class TestFixtureComponent {
pagerPreviousIcon = '';
pagerNextIcon = '';
totalMessage = '';
footerTemplate?: { template: TemplateRef<any> };
footerTemplate?: { template: Signal<TemplateRef<any>> };
selectedCount = 0;
selectedMessage?: string;

Expand All @@ -263,8 +263,7 @@ class TestFixtureComponent {
* selectively be passed to the DatatableFooterComponent
* in these unit tests
*/
@ViewChild('testTemplate', { read: TemplateRef, static: true })
testTemplate!: TemplateRef<any>;
readonly testTemplate = viewChild.required('testTemplate', { read: TemplateRef });

onPageEvent() {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import { DataTablePagerComponent } from './pager.component';
[ngClass]="{ 'selected-count': selectedMessage() }"
[style.height.px]="footerHeight()"
>
@if (footerTemplate()?.template) {
@let footerTemplate = this.footerTemplate()?.template();
@if (footerTemplate) {
<ng-template
[ngTemplateOutlet]="footerTemplate()!.template!"
[ngTemplateOutlet]="footerTemplate"
[ngTemplateOutletContext]="templateContext()"
/>
} @else {
Expand Down Expand Up @@ -64,9 +65,9 @@ export class DataTableFooterComponent {

readonly page = output<PagerPageEvent>();

readonly isVisible = computed(() => this.rowCount() / this.pageSize() > 1);
readonly curPage = computed(() => this.offset() + 1);
readonly templateContext: Signal<FooterContext> = computed(() => ({
protected readonly isVisible = computed(() => this.rowCount() / this.pageSize() > 1);
protected readonly curPage = computed(() => this.offset() + 1);
protected readonly templateContext: Signal<FooterContext> = computed(() => ({
rowCount: this.rowCount(),
pageSize: this.pageSize(),
selectedCount: this.selectedCount(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ContentChild, Directive, Input, TemplateRef } from '@angular/core';
import { Directive, TemplateRef, input, contentChild, computed } from '@angular/core';

import { FooterContext } from '../../types/public.types';
import { DataTableFooterTemplateDirective } from './footer-template.directive';
Expand All @@ -7,13 +7,13 @@ import { DataTableFooterTemplateDirective } from './footer-template.directive';
selector: 'ngx-datatable-footer'
})
export class DatatableFooterDirective {
@Input('template')
_templateInput?: TemplateRef<FooterContext>;
readonly _templateInput = input<TemplateRef<FooterContext>>(undefined, { alias: 'template' });

@ContentChild(DataTableFooterTemplateDirective, { read: TemplateRef })
_templateQuery?: TemplateRef<FooterContext>;
private readonly _templateQuery = contentChild(DataTableFooterTemplateDirective, {
read: TemplateRef
});

get template(): TemplateRef<FooterContext> | undefined {
return this._templateInput ?? this._templateQuery;
}
readonly template = computed(() => {
return this._templateInput() ?? this._templateQuery();
});
}
Loading