GUI --Added cleanup on scope destroy for sample and device views.
Change-Id: Ia1656eb3987f2f896fa7d6d2cec2860495ce36d7
Showing
2 changed files
with
63 additions
and
43 deletions
... | @@ -22,7 +22,9 @@ | ... | @@ -22,7 +22,9 @@ |
22 | 'use strict'; | 22 | 'use strict'; |
23 | 23 | ||
24 | angular.module('ovDevice', []) | 24 | angular.module('ovDevice', []) |
25 | - .controller('OvDeviceCtrl', ['$log', '$scope', '$location', 'RestService', | 25 | + .controller('OvDeviceCtrl', |
26 | + ['$log', '$scope', '$location', 'RestService', | ||
27 | + | ||
26 | function ($log, $scope, $location, rs) { | 28 | function ($log, $scope, $location, rs) { |
27 | var self = this; | 29 | var self = this; |
28 | self.deviceData = []; | 30 | self.deviceData = []; |
... | @@ -38,6 +40,11 @@ | ... | @@ -38,6 +40,11 @@ |
38 | }; | 40 | }; |
39 | $scope.sortCallback(); | 41 | $scope.sortCallback(); |
40 | 42 | ||
43 | + // Cleanup on destroyed scope | ||
44 | + $scope.$on('$destroy', function () { | ||
45 | + | ||
46 | + }); | ||
47 | + | ||
41 | $log.log('OvDeviceCtrl has been created'); | 48 | $log.log('OvDeviceCtrl has been created'); |
42 | }]); | 49 | }]); |
43 | }()); | 50 | }()); | ... | ... |
... | @@ -24,6 +24,9 @@ | ... | @@ -24,6 +24,9 @@ |
24 | // injected refs | 24 | // injected refs |
25 | var $log, tbs, flash; | 25 | var $log, tbs, flash; |
26 | 26 | ||
27 | + // configuration | ||
28 | + var tbid = 'sample-toolbar'; | ||
29 | + | ||
27 | // internal state | 30 | // internal state |
28 | var togFnDiv, radFnP; | 31 | var togFnDiv, radFnP; |
29 | 32 | ||
... | @@ -50,47 +53,57 @@ | ... | @@ -50,47 +53,57 @@ |
50 | .style('color', '#369'); | 53 | .style('color', '#369'); |
51 | } | 54 | } |
52 | 55 | ||
56 | + | ||
57 | + // define the controller | ||
58 | + | ||
53 | angular.module('ovSample', ['onosUtil']) | 59 | angular.module('ovSample', ['onosUtil']) |
54 | - .controller('OvSampleCtrl', ['$log', 'ToolbarService', 'FlashService', | 60 | + .controller('OvSampleCtrl', |
55 | - function (_$log_, _tbs_, _flash_) { | 61 | + ['$scope', '$log', 'ToolbarService', 'FlashService', |
56 | - var self = this, | 62 | + |
57 | - toolbar, | 63 | + function ($scope, _$log_, _tbs_, _flash_) { |
58 | - rset; | 64 | + var self = this, |
59 | - | 65 | + toolbar, |
60 | - $log = _$log_; | 66 | + rset; |
61 | - tbs = _tbs_; | 67 | + |
62 | - flash = _flash_; | 68 | + $log = _$log_; |
63 | - | 69 | + tbs = _tbs_; |
64 | - self.message = 'Hey there folks!'; | 70 | + flash = _flash_; |
65 | - | 71 | + |
66 | - togFnDiv = d3.select('#ov-sample') | 72 | + self.message = 'Hey there folks!'; |
67 | - .append('div') | 73 | + |
68 | - .text('Look at me!') | 74 | + togFnDiv = d3.select('#ov-sample') |
69 | - .style({ | 75 | + .append('div') |
70 | - display: 'none', | 76 | + .text('Look at me!') |
71 | - color: 'rgb(204, 89, 81)', | 77 | + .style({ |
72 | - 'font-size': '20pt' | 78 | + display: 'none', |
73 | - }); | 79 | + color: 'rgb(204, 89, 81)', |
74 | - | 80 | + 'font-size': '20pt' |
75 | - radFnP = d3.select('#ov-sample') | 81 | + }); |
76 | - .append('p') | 82 | + |
77 | - .style('font-size', '16pt'); | 83 | + radFnP = d3.select('#ov-sample') |
78 | - | 84 | + .append('p') |
79 | - toolbar = tbs.createToolbar('sample'); | 85 | + .style('font-size', '16pt'); |
80 | - rset = [ | 86 | + |
81 | - { gid: 'checkMark', cb: checkFn }, | 87 | + toolbar = tbs.createToolbar(tbid); |
82 | - { gid: 'xMark', cb: xMarkFn }, | 88 | + rset = [ |
83 | - { gid: 'bird', cb: birdFn } | 89 | + { gid: 'checkMark', cb: checkFn }, |
84 | - ]; | 90 | + { gid: 'xMark', cb: xMarkFn }, |
85 | - | 91 | + { gid: 'bird', cb: birdFn } |
86 | - toolbar.addButton('demo-button', 'crown', btnFn); | 92 | + ]; |
87 | - toolbar.addToggle('demo-toggle', 'chain', false, togFn); | 93 | + |
88 | - toolbar.addSeparator(); | 94 | + toolbar.addButton('demo-button', 'crown', btnFn); |
89 | - toolbar.addRadioSet('demo-radio', rset); | 95 | + toolbar.addToggle('demo-toggle', 'chain', false, togFn); |
90 | - toolbar.hide(); | 96 | + toolbar.addSeparator(); |
91 | - | 97 | + toolbar.addRadioSet('demo-radio', rset); |
92 | - checkFn(); | 98 | + toolbar.hide(); |
93 | - | 99 | + |
94 | - $log.log('OvSampleCtrl has been created'); | 100 | + checkFn(); |
95 | - }]); | 101 | + |
102 | + // Clean up on destroyed scope | ||
103 | + $scope.$on('$destroy', function () { | ||
104 | + tbs.destroyToolbar(tbid); | ||
105 | + }); | ||
106 | + | ||
107 | + $log.log('OvSampleCtrl has been created'); | ||
108 | + }]); | ||
96 | }()); | 109 | }()); | ... | ... |
-
Please register or login to post a comment