diff --git a/npm/ng-packs/packages/components/chart.js/src/chart.component.ts b/npm/ng-packs/packages/components/chart.js/src/chart.component.ts index 9ab84aedcd..d4e697b48d 100644 --- a/npm/ng-packs/packages/components/chart.js/src/chart.component.ts +++ b/npm/ng-packs/packages/components/chart.js/src/chart.component.ts @@ -1,17 +1,17 @@ -import { - AfterViewInit, - ChangeDetectionStrategy, - ChangeDetectorRef, - Component, - ElementRef, - EventEmitter, - Input, - OnChanges, - OnDestroy, - Output, - SimpleChanges, - ViewChild, - inject +import { + AfterViewInit, + ChangeDetectionStrategy, + ChangeDetectorRef, + Component, + ElementRef, + EventEmitter, + OnDestroy, + Output, + ViewChild, + effect, + inject, + input, + untracked, } from '@angular/core'; let Chart: any; @@ -21,13 +21,13 @@ let Chart: any; template: `
@@ -35,32 +35,39 @@ let Chart: any; changeDetection: ChangeDetectionStrategy.OnPush, exportAs: 'abpChart', }) -export class ChartComponent implements AfterViewInit, OnDestroy, OnChanges { +export class ChartComponent implements AfterViewInit, OnDestroy { el = inject(ElementRef); private cdr = inject(ChangeDetectorRef); - @Input() type!: string; - - @Input() data: any = {}; - - @Input() options: any = {}; - - @Input() plugins: any[] = []; - - @Input() width?: string; - - @Input() height?: string; - - @Input() responsive = true; + readonly type = input.required(); + readonly data = input({}); + readonly options = input({}); + readonly plugins = input([]); + readonly width = input(); + readonly height = input(); + readonly responsive = input(true); @Output() dataSelect = new EventEmitter(); - @Output() initialized = new EventEmitter(); @ViewChild('canvas') canvas!: ElementRef; chart: any; + constructor() { + effect(() => { + const data = this.data(); + const options = this.options(); + + untracked(() => { + if (this.chart) { + this.chart.destroy(); + this.initChart(); + } + }); + }); + } + ngAfterViewInit() { import('chart.js/auto').then(module => { Chart = module.default; @@ -91,19 +98,19 @@ export class ChartComponent implements AfterViewInit, OnDestroy, OnChanges { } private initChart = () => { - const opts = this.options || {}; - opts.responsive = this.responsive; + const opts = this.options() || {}; + opts.responsive = this.responsive(); // allows chart to resize in responsive mode - if (opts.responsive && (this.height || this.width)) { + if (opts.responsive && (this.height() || this.width())) { opts.maintainAspectRatio = false; } this.chart = new Chart(this.canvas.nativeElement, { - type: this.type as any, - data: this.data, - options: this.options, - plugins: this.plugins, + type: this.type() as any, + data: this.data(), + options: this.options(), + plugins: this.plugins(), }); }; @@ -140,13 +147,5 @@ export class ChartComponent implements AfterViewInit, OnDestroy, OnChanges { this.chart = null; } } - - ngOnChanges(changes: SimpleChanges) { - if (!this.chart) return; - - if (changes.data?.currentValue || changes.options?.currentValue) { - this.chart.destroy(); - this.initChart(); - } - } } + diff --git a/npm/ng-packs/packages/components/extensible/src/lib/components/abstract-actions/abstract-actions.component.ts b/npm/ng-packs/packages/components/extensible/src/lib/components/abstract-actions/abstract-actions.component.ts index 465a18b813..e162310044 100644 --- a/npm/ng-packs/packages/components/extensible/src/lib/components/abstract-actions/abstract-actions.component.ts +++ b/npm/ng-packs/packages/components/extensible/src/lib/components/abstract-actions/abstract-actions.component.ts @@ -1,4 +1,4 @@ -import { Directive, Injector, Input, inject } from '@angular/core'; +import { Directive, Injector, inject, input } from '@angular/core'; import { ActionData, ActionList, InferredAction } from '../../models/actions'; import { ExtensionsService } from '../../services/extensions.service'; import { EXTENSIONS_ACTION_TYPE, EXTENSIONS_IDENTIFIER } from '../../tokens/extensions.token'; @@ -14,7 +14,7 @@ export abstract class AbstractActionsComponent< readonly getInjected: InferredData['getInjected']; - @Input() record!: InferredData['record']; + record = input.required>(); protected constructor() { const injector = inject(Injector); @@ -27,3 +27,4 @@ export abstract class AbstractActionsComponent< this.actionList = extensions[type].get(name).actions as unknown as L; } } + diff --git a/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-form/extensible-form-prop.component.html b/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-form/extensible-form-prop.component.html index 2f9df1ae00..4daf6fb854 100644 --- a/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-form/extensible-form-prop.component.html +++ b/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-form/extensible-form-prop.component.html @@ -1,34 +1,34 @@ - - @switch (getComponent(prop)) { + + @switch (getComponent(prop())) { @case ('template') { - + } }
- @switch (getComponent(prop)) { + @switch (getComponent(prop())) { @case ('input') { - } @case ('hidden') { - + } @case ('checkbox') {
-
} @case ('select') { - - +
} @case ('date') { - } @case ('time') { - + } @case ('dateTime') { - + } @case ('textarea') { - } @case ('passwordinputgroup') {
- +