Adding additional data to the model of diagram

Hi,
1- I want to add some new attributes to the model of a diagram before sending it to server with API.

 saveDiagram(){
 let newModel = this.diagram.model;
 let obj = {
 text:"test",
 description:"test"
 }
 let newModel2 = {...newModel , ...obj};
 newModel2 = newModel2.toJson();

but there’s an error for toJson function.
is there a way to do this?

2- If I don’t want to let userto delete particular nodes based on their id’s how can I have access to that Id in the SelectionDeleting addDiagramListener?

  1. You probably want to add your extra properties to Model.modelData.

  2. The “SelectionDeleting” event has the selection collection as e.subject. So you could iterate over that collection using

myDiagram.addDiagramListener("SelectionDeleting", function(e) {
  var partIt = e.subject.iterator;
  partIt.each(function(p) {
    // check p.key
    ...
  });
});

thanks for your reply. can you please explain more about the second question?
I don’t know how to prevent deleting node after I detected the node’s Id. how can I stop deleting process?
btw I’m coding in Angular 8

this.diagram.addDiagramListener("SelectionDeleting", (e)=>{
    let part = e.subject.first();
    if(!part.jb.stateId){
        //what should I do here?
    }
})

Set part.isSelected = false;. This removes it from the selection so it won’t be deleted.