Posted 11 February 2021, 4:30 am EST
We are getting runtime errors in angular when built with AOT enabled. The issue is caused when we are using wjFlexGridCellTemplate inside an object extending WjFlexGridColumn.
The runtime error occurs in WjFlexGridCellTemplate._attachToControl() where ownerControl is undefined.
I tracked the problem to the usage of instanceof in the WjFlexGridCellTemplate constructor. There seems to be multiple versions of the WjFlexGridColumn prototype depending on if you are using AOT or JIT.
function WjFlexGridCellTemplate(e, t, r, o, i, n) {
this.viewContainerRef = e;
this.templateRef = t;
this.elRef = r;
this.cdRef = n;
this.autoSizeRows = !0;
this.forceFullEdit = !0;
console.log('WjFlexGridCellTemplate o ', o);
if (o instanceof WjFlexGrid) {
this.grid = o;
console.log('WjFlexGridCellTemplate o instanceof WjFlexGrid', this);
}
else if (o instanceof WjFlexGridColumn) {
this.column = o;
this.grid = wijmo_angular2_directivebase_1.WjDirectiveBehavior.getBehavior(
o
).parentBehavior.directive;
console.log('WjFlexGridCellTemplate o instanceof WjFlexGridColumn', this);
}
}
Example extended component
import { Component, forwardRef } from '@angular/core';
import { WjFlexGridColumn, wjFlexGridColumnMeta } from '@grapecity/wijmo.angular2.grid';
@Component({
selector: 'hc-test-grid-column',
template: `<div><ng-content></ng-content></div>`,
// tslint:disable-next-line:use-input-property-decorator
inputs: wjFlexGridColumnMeta.inputs,
// tslint:disable-next-line:use-output-property-decorator
outputs: wjFlexGridColumnMeta.outputs,
providers: [
{ provide: 'WjComponent', useExisting: forwardRef(() => TestColumnComponent) },
...wjFlexGridColumnMeta.providers,
],
})
export class TestColumnComponent extends WjFlexGridColumn { }
Usage
<wj-flex-grid [itemsSource]="itemsSource">
<hc-test-grid-column width="*" header="grid-column.header">
<ng-template wjFlexGridCellTemplate cellType="Cell" let-cell="cell">
wjFlexGridCellTemplate {{ cell.item.val }}
</ng-template>
</hc-test-grid-column>
</wj-flex-grid>
I can eliminate the error in AOT if I change the import in TestColumnComponent to the following:
import { WjFlexGridColumn, wjFlexGridColumnMeta } from ‘@grapecity/wijmo.angular2.grid/index’;
This causes an error in JIT compilation instead. I should be able to use the same version in both JIT and AOT builds. (We use JIT for local dev, AOT for prod).