3

I'm getting Type Error when trying to destroy the viewer in Angular2.

for that I tried this code,

ngOnDestroy() {
        if (this.viewer && this.viewer.running) {
            this.viewer.tearDown();
            this.viewer.finish();
            this.viewer = null;
        }
    }

But getting Error like below:

TypeError: Cannot read property 'updateMaterials' of null
    at tick (viewer3D.js:27154)
    at animloop (viewer3D.js:27631)
    at ZoneDelegate.invokeTask (zone.js:356)
    at Object.onInvokeTask (node_modules/@angular/core//bundles/core.umd.js:9091)
    at ZoneDelegate.invokeTask (zone.js:355)
    at Zone.runTask (zone.js:256)
    at ZoneTask.invoke (zone.js:423)

How can I fix this issue using Angular2?

1 Answers1

0

Please check this answer. Additionally, you may also need to .impl.unloadCurrentModel()

Augusto Goncalves
  • 8,493
  • 2
  • 17
  • 44
  • @RuhamaDavid I tried your original code, and works fine. I'm guessing your Angular code still trying to access the Viewer and causing this error (updateMaterials occurs with the render). The other answer suggests to keep the Viewer running when you navigate between states/pages on your SPA. – Augusto Goncalves Jul 18 '18 at 11:20