modelData data binding op clipboard copy


I have a data binding in my node template that depends on modelData with a conversion function (example):

(value, target: go.Node) => {
  if (!target.diagram) {
    throw new ValueError(`Could not obtain diagram from target node ${target}`);
  return target.diagram.model.modelData[value];

This works when creating new nodes and copying nodes using SelectionCopied (holding ctrl). However, when add a selection of nodes to my clipboard using ctrl + c, this binding gets evaluated and it throws the value error above (apparently the node is then not associated to the diagram`. How should I address this issue?


That’s correct – there’s no Diagram associated with the clipboard’s Model.

The node data’s properties are copied OK, aren’t they? So what is really the problem? Even continuing to throw an error is OK, although I suggest that you instead just return a default value.

They are but I would like to access the global modelData and I use the Diagram for this → diagram.model.modelData. Is there an other way to obtain the modelData without having a Diagram?

I’m not sure what you want to do. Perhaps a Binding.ofModel will get you what you want.

Thanks, that would work for getting the modelData but I would like to access the nodeData as well. Is this possible?

Maybe you can get via the second argument’s I haven’t tried it when the clipboard is involved…

I tried replacing my binding to:


However, now the initialization of my nodes already fails because seems to be undefined on the target (second argument of the conversion function)


nevermind, I can use, that seems to do the trick. Thanks!

This also seems to work when the clipboard is involved, thanks!