ERROR TypeError: Cannot read property 'endUpdate' of undefined
Bug Report
Please see also ticket T681702
Package versions: devexteme version: 18.2.6 (but problem is present also in previous versions 18.x) devextreme-angular version: 18.2.6
Disclaimer As mentioned in Devexpress official documentation, I understand that deriving from DevExtreme controls is not supported.
Solution As written in the mentioned ticket, I think that the issue should be solved by changing the code in component.ts, line 216, as follows:
ngAfterViewInit() {
if (this.instance) {
this._initTemplates();
if (this.createInstanceOnInit) {
this.instance.endUpdate();
}
}
}
Hi,
We have discussed this logic with our R&D team and concluded that it is unclear in which situation the instance cannot be defined in the ngAfterViewInit. Anyway, since the custom inheritance is not officially supported, I am not sure that we can make any changes on our side. Would you please clarify what customization you wish to implement in this manner? Perhaps, we can find an alternative solution.
Hi Alexander,
thank you very much for answering. As you can read on the original ticket, I found a workaround and it's working fine.
I understand your comment, I simply thought that checking for undefined on this.instance would increase robustness of code. I can see that you check this.instance in many other methods in the same class, but not in ngAfterViewInit.
Of course, I also understand that inheritance is not officially supported but right now I cannot find an alternative solution (in other cases, I encapsulated DX components into a custom component avoiding inheritance). I can mention a simple case where we derived from DxToolbarComponent to have a common toolbar used on all pages of our application with a set of predefined items, features (a superset of DxToolbar). At the same time we need the toolbar to be fully customized inside HTML using inner dx-items as in the following example:
<custom-toolbar [title]="model.title">
<dxi-item widget="dxButton" location="after" [options]="{icon: 'plus', type: 'success', onClick: addNewItem}"></dxi-item>
</custom-toolbar>
As you can see, we're using dxi-item inside our custom control and it's working as expected. But we have other cases thus we derived other DX components.
Thanks.
While it might require less code initially, maintaining custom components which extend DevExtreme components and use internal API might be a bit more work in the long run.
The "custom-toolbar" with "dxi-item" child elements could also be implemented without deriving DevExtreme toolbar by using Angular ContentChildren selector.
Hi Tomas, thank you very much for following up with my message.
Of course, I know about ContentChildren; we're already using it in our components. I mentioned that case (dxi-item) just to make a simple example but we have more complex cases. Anyway, even in the mentioned case using ContentChildren does not have the same behavior as extending the dx-toolbar.
At the same time I completely agree with you about less code initially => more work in the long. We always try to avoid to extend DevExtreme components (and, general speaking, with any other vendor's component) ... but sometime we were not able to find alternative solution.
Thank you so much.