diff --git a/public/app/features/dashboard/dashboard_ctrl.ts b/public/app/features/dashboard/dashboard_ctrl.ts index 016bb87df3a..075e3dcaa8f 100644 --- a/public/app/features/dashboard/dashboard_ctrl.ts +++ b/public/app/features/dashboard/dashboard_ctrl.ts @@ -117,9 +117,10 @@ export class DashboardCtrl { $timeout.cancel(resizeEventTimeout); resizeEventTimeout = $timeout(function() { $scope.$broadcast('render'); }, 200); }); - var unbind = $scope.$on('$destroy', function() { + + $scope.$on('$destroy', function() { angular.element(window).unbind('resize'); - unbind(); + $scope.dashboard.destroy(); }); }; @@ -129,10 +130,10 @@ export class DashboardCtrl { } init(dashboard) { - this.$scope.registerWindowResizeEvent(); this.$scope.onAppEvent('show-json-editor', this.$scope.showJsonEditor); this.$scope.onAppEvent('template-variable-value-updated', this.$scope.templateVariableUpdated); this.$scope.setupDashboard(dashboard); + this.$scope.registerWindowResizeEvent(); } } diff --git a/public/app/features/dashboard/model.ts b/public/app/features/dashboard/model.ts index aa75800817f..6dc7460dc03 100644 --- a/public/app/features/dashboard/model.ts +++ b/public/app/features/dashboard/model.ts @@ -247,6 +247,13 @@ export class DashboardModel { moment.utc(date).format(format); } + destroy() { + this.events.removeAllListeners(); + for (let row of this.rows) { + row.events.removeAllListeners(); + } + } + getRelativeTime(date) { date = moment.isMoment(date) ? date : moment(date); diff --git a/public/app/features/dashboard/row/row.ts b/public/app/features/dashboard/row/row.ts index b996c0109c6..4c86755537c 100644 --- a/public/app/features/dashboard/row/row.ts +++ b/public/app/features/dashboard/row/row.ts @@ -212,7 +212,11 @@ coreModule.directive('panelDropZone', function($timeout) { row.events.on('panel-added', updateState); row.events.on('span-changed', updateState); - //scope.$watchGroup(['ctrl.row.panels.length', 'ctrl.dashboard.editMode', 'ctrl.row.span'], updateState); + scope.$on('$destroy', () => { + row.events.off('panel-added', updateState); + row.events.off('span-changed', updateState); + }); + // scope.$watchGroup(['ctrl.row.panels.length', 'ctrl.dashboard.editMode', 'ctrl.row.span'], updateState); scope.$on("ANGULAR_DRAG_START", function() { indrag = true; diff --git a/public/app/features/dashboard/unsavedChangesSrv.js b/public/app/features/dashboard/unsavedChangesSrv.js index 60b8f24c462..0dd96549867 100644 --- a/public/app/features/dashboard/unsavedChangesSrv.js +++ b/public/app/features/dashboard/unsavedChangesSrv.js @@ -12,16 +12,15 @@ function(angular, _) { function Tracker(dashboard, scope) { var self = this; - this.original = dashboard.getSaveModelClone(); this.current = dashboard; this.originalPath = $location.path(); this.scope = scope; // register events scope.onAppEvent('dashboard-saved', function() { - self.original = self.current.getSaveModelClone(); - self.originalPath = $location.path(); - }); + this.original = this.current.getSaveModelClone(); + this.originalPath = $location.path(); + }.bind(this)); $window.onbeforeunload = function() { if (self.ignoreChanges()) { return; } @@ -44,6 +43,11 @@ function(angular, _) { }); } }); + + // wait for different services to patch the dashboard (missing properties) + $timeout(function() { + self.original = dashboard.getSaveModelClone(); + }, 1000); } var p = Tracker.prototype; @@ -153,8 +157,7 @@ function(angular, _) { this.Tracker = Tracker; this.init = function(dashboard, scope) { - // wait for different services to patch the dashboard (missing properties) - $timeout(function() { new Tracker(dashboard, scope); }, 1200); + new Tracker(dashboard, scope); }; }); }); diff --git a/public/app/features/panel/panel_ctrl.ts b/public/app/features/panel/panel_ctrl.ts index 52104e5411d..c9fb00f58fe 100644 --- a/public/app/features/panel/panel_ctrl.ts +++ b/public/app/features/panel/panel_ctrl.ts @@ -50,11 +50,9 @@ export class PanelCtrl { $scope.$on("refresh", () => this.refresh()); $scope.$on("render", () => this.render()); - - var unbindDestroy = $scope.$on("$destroy", () => { + $scope.$on("$destroy", () => { this.events.emit('panel-teardown'); this.events.removeAllListeners(); - unbindDestroy(); }); }