Skip to content

Commit 7d11540

Browse files
fix samples/angular.html
replacing Diagram.model might cause selection change which should not call scope.$apply() at that time
1 parent 86ec167 commit 7d11540

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

samples/angular.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<script src="go.js"></script>
99
<link href="../assets/css/goSamples.css" rel="stylesheet" type="text/css" /> <!-- you don't need to use this -->
1010
<script src="goSamples.js"></script> <!-- this is only for the GoJS Samples framework -->
11-
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.2/angular.min.js"></script>
11+
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.2/angular.min.js"></script>
1212
<script id="code">
1313
angular.module('minimal', [])
1414
.directive('goDiagram', function() {
@@ -54,11 +54,14 @@
5454
scope.$watch("model", function(newmodel) {
5555
var oldmodel = diagram.model;
5656
if (oldmodel !== newmodel) {
57+
diagram.removeDiagramListener("ChangedSelection", updateSelection);
5758
diagram.model = newmodel;
59+
diagram.addDiagramListener("ChangedSelection", updateSelection);
5860
}
5961
});
6062

6163
scope.$watch("model.selectedNodeData.name", function(newname) {
64+
if (!diagram.model.selectedNodeData) return;
6265
// disable recursive updates
6366
diagram.removeModelChangedListener(updateAngular);
6467
// change the name
@@ -72,11 +75,12 @@
7275
});
7376

7477
// update the model when the selection changes
75-
diagram.addDiagramListener("ChangedSelection", function(e) {
78+
function updateSelection(e) {
7679
var selnode = diagram.selection.first();
7780
diagram.model.selectedNodeData = (selnode instanceof go.Node ? selnode.data : null);
7881
scope.$apply();
79-
});
82+
}
83+
diagram.addDiagramListener("ChangedSelection", updateSelection);
8084
}
8185
};
8286
})

0 commit comments

Comments
 (0)