diff --git a/src/app/modules/angular-slickgrid/components/__tests__/angular-slickgrid.component.spec.ts b/src/app/modules/angular-slickgrid/components/__tests__/angular-slickgrid.component.spec.ts index ea609ae2a..5d6755c71 100644 --- a/src/app/modules/angular-slickgrid/components/__tests__/angular-slickgrid.component.spec.ts +++ b/src/app/modules/angular-slickgrid/components/__tests__/angular-slickgrid.component.spec.ts @@ -454,13 +454,14 @@ describe('Angular-Slickgrid Custom Component instantiated via Constructor', () = expect(component.gridOptions.enableMouseWheelScrollHandler).toBeTrue(); }); - it('should throw an error when [gridOptions] and/or [columnDefinitions] is undefined', (done) => { + it('should throw an error when [columnDefinitions] is undefined', (done) => { try { - component.gridOptions = undefined as any; + component.columnDefinitions = '' as any; + component.gridOptions = gridOptions; component.ngAfterViewInit(); component.dataset = []; } catch (e: any) { - expect(e.toString()).toContain('Using `` requires [gridOptions] and [columnDefinitions]'); + expect(e.toString()).toContain('Using `` requires [columnDefinitions]'); component.destroy(); done(); } diff --git a/src/app/modules/angular-slickgrid/components/angular-slickgrid.component.ts b/src/app/modules/angular-slickgrid/components/angular-slickgrid.component.ts index 275068586..715a8cab4 100644 --- a/src/app/modules/angular-slickgrid/components/angular-slickgrid.component.ts +++ b/src/app/modules/angular-slickgrid/components/angular-slickgrid.component.ts @@ -156,7 +156,7 @@ export class AngularSlickgridComponent implements AfterViewInit, On @Input() customDataView: any; @Input() gridId = ''; - @Input() gridOptions!: GridOption; + @Input() gridOptions: GridOption = {}; @Input() get paginationOptions(): Pagination | undefined { @@ -359,8 +359,8 @@ export class AngularSlickgridComponent implements AfterViewInit, On } ngAfterViewInit() { - if (!this.gridOptions || !this.columnDefinitions) { - throw new Error('Using `` requires [gridOptions] and [columnDefinitions], it seems that you might have forgot to provide them since at least of them is undefined.'); + if (!this.columnDefinitions) { + throw new Error('Using `` requires [columnDefinitions], it seems that you might have forgot to provide the missing bindable input.'); } this.initialization(this._eventHandler); @@ -424,8 +424,10 @@ export class AngularSlickgridComponent implements AfterViewInit, On } this.backendServiceApi = undefined; } - for (const prop of Object.keys(this.columnDefinitions)) { - (this.columnDefinitions as any)[prop] = null; + if (this.columnDefinitions) { + for (const prop of Object.keys(this.columnDefinitions)) { + (this.columnDefinitions as any)[prop] = null; + } } for (const prop of Object.keys(this.sharedService)) { (this.sharedService as any)[prop] = null; @@ -459,7 +461,7 @@ export class AngularSlickgridComponent implements AfterViewInit, On } emptyGridContainerElm() { - const gridContainerId = this.gridOptions?.gridContainerId ?? 'grid1'; + const gridContainerId = this.gridOptions?.gridContainerId || 'grid1'; const gridContainerElm = document.querySelector(`#${gridContainerId}`); emptyElement(gridContainerElm); } @@ -502,7 +504,7 @@ export class AngularSlickgridComponent implements AfterViewInit, On this._eventPubSubService.publish('onBeforeGridCreate', true); // make sure the dataset is initialized (if not it will throw an error that it cannot getLength of null) - this._dataset = this._dataset || []; + this._dataset ||= []; this.gridOptions = this.mergeGridOptions(this.gridOptions); this._paginationOptions = this.gridOptions?.pagination; this.locales = this.gridOptions?.locales ?? Constants.locales;