|
8 | 8 | <script src="go.js"></script> |
9 | 9 | <link href="../assets/css/goSamples.css" rel="stylesheet" type="text/css" /> <!-- you don't need to use this --> |
10 | 10 | <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> |
12 | 12 | <script id="code"> |
13 | 13 | angular.module('minimal', []) |
14 | 14 | .directive('goDiagram', function() { |
|
54 | 54 | scope.$watch("model", function(newmodel) { |
55 | 55 | var oldmodel = diagram.model; |
56 | 56 | if (oldmodel !== newmodel) { |
| 57 | + diagram.removeDiagramListener("ChangedSelection", updateSelection); |
57 | 58 | diagram.model = newmodel; |
| 59 | + diagram.addDiagramListener("ChangedSelection", updateSelection); |
58 | 60 | } |
59 | 61 | }); |
60 | 62 |
|
61 | 63 | scope.$watch("model.selectedNodeData.name", function(newname) { |
| 64 | + if (!diagram.model.selectedNodeData) return; |
62 | 65 | // disable recursive updates |
63 | 66 | diagram.removeModelChangedListener(updateAngular); |
64 | 67 | // change the name |
|
72 | 75 | }); |
73 | 76 |
|
74 | 77 | // update the model when the selection changes |
75 | | - diagram.addDiagramListener("ChangedSelection", function(e) { |
| 78 | + function updateSelection(e) { |
76 | 79 | var selnode = diagram.selection.first(); |
77 | 80 | diagram.model.selectedNodeData = (selnode instanceof go.Node ? selnode.data : null); |
78 | 81 | scope.$apply(); |
79 | | - }); |
| 82 | + } |
| 83 | + diagram.addDiagramListener("ChangedSelection", updateSelection); |
80 | 84 | } |
81 | 85 | }; |
82 | 86 | }) |
|
0 commit comments