Making a change to the model using AngularJS

Hello,

I am using a form with an input field to change the label of the currently-selected node in the diagram, outside of the diagram itself.

Nodes have their names bound the usual way to the model:
$(go.TextBlock, new go.Binding(“text”, “name”))

In the form the input used to edit the name uses an Angular binding:

Now, to tell the diagram to take the change into account, I need to call setDataProperty within a transaction.

My code derives from your Angular example: when a transaction is committed, $apply is called. But when the name is being changed in the input field and that input is bound, this triggers an apply too, so I get an error that I am trying to call $apply during an $apply phase.

Basically, I don’t know how or when to call setDataProperty in such a situation. Would you be able to provide me with some tips?

Thanks,
Marc.

Take a look at [EDIT: now a standard sample] http://gojs.net/latest/samples/angular.html for one way to solve that problem.

There’s probably a more general and/or elegant way to do that, but I haven’t had time to investigate it.

Thank you for this. After looking at what you did, I found a more generic way of handling such issues, in case this would help other people: just change the updateAngular function to the following:

function updateAngular(e) {
if (e.isTransactionFinished && $rootScope.$$phase != “$apply” && $rootScope.$$phase != “$digest”) {
scope.$apply();
}
}

Marc.