Click event is not strongly typed

Hi there,

I have a diagram - that renders fine and have set up the (click) handler as follows:

<ejs-diagram

  #diagram

  id="diagram"

  width="100%"

  height="580px"

  [getConnectorDefaults]="connDefaults"

  [getNodeDefaults]="nodeDefaults"

  [tool]="tool"

  [layout]="layout"

  [dataSourceSettings]="data"

  [snapSettings]="snapSettings"

  (created)="created()"

  (click)="handleClick($event)"

></ejs-diagram>


My event handler looks like this:

  handleClick(args: IClickEventArgs): void {

    console.log(args);

    if (args.element instanceof Node) {

      console.log('We got a Node');

    }

  }


When I look at the output of the console.log I can see that the type of the element is Node. However, the if statement is never true. Instead it shows that it is type object. Why would this be please?





1 Reply

BM Balasubramanian Manikandan Syncfusion Team December 9, 2022 02:04 PM UTC


We suspect that you would have not imported Node in your sample. So only the if conditions fails in the click event. We have provided a sample to achieve your requirement. Refer to the below mentioned code example and sample.


Code Snippet:

import {

  Node,

} from '@syncfusion/ej2-diagrams';



Sample:

https://stackblitz.com/edit/angular-pkofck?file=app.component.html,app.component.ts



Loader.
Up arrow icon