Skip to content
This repository was archived by the owner on Jan 21, 2025. It is now read-only.
This repository was archived by the owner on Jan 21, 2025. It is now read-only.

Type Error is thrown on invoking fatory function imported from mxgraph in Angular 13 #50

@Dhawaldeep

Description

@Dhawaldeep

Following type error is thrown while invoking factory function imported from mxgraph

Uncaught TypeError: Cannot set properties of undefined (setting 'mxBasePath')

This happens only on Angular 13 stable version and not on angular 12.

Please see the below public repository link & code snippets for reference
https://github.com/Dhawaldeep/mxgraph-angular-tteen

src/app/mxgraph-engine/mxgraph.ts

import factory from 'mxgraph';
declare global {
  interface Window {
    mxBasePath: string;
  }
}

window['mxBasePath'] = '../../assets/mxgraph';

export default factory({
  mxBasePath: '../../assets/mxgraph',
});

src/app/mxgraph-engine/index.d.ts

declare module 'mxgraph';

src/app/app.component.ts

.........
import mx from './mxgraph-engine/mxgraph';
import '@typed-mxgraph/typed-mxgraph';
.........
export class AppComponent implements AfterViewInit {
  @ViewChild('mxgraphEl') mxgraphEl: ElementRef<HTMLDivElement>;

  ngAfterViewInit(): void {
    if(mx.mxClient.isBrowserSupported()) {
      console.log('Yes! Yes!');
    }
    const graph = new mx.mxGraph(this.mxgraphEl.nativeElement);
    const model = graph.getModel();
    model.beginUpdate();
    try {
      graph.insertVertex(graph.getDefaultParent(), '', 'TEST', 0, 0, 100, 100);
    } finally {
      model.endUpdate();
    }
  }
}

src/app/app.component.html

<div #mxgraphEl></div>

package.json

....
dependencies: {
..,,.
 "mxgraph": "^4.2.2",
....
},
.....
devDependencies: {
.....
"@typed-mxgraph/typed-mxgraph": "^1.0.5",
.....
}

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions