diff --git a/public/app/controllers/grafanaCtrl.js b/public/app/controllers/grafanaCtrl.js index 16e505a68dc..77c4d5f70c5 100644 --- a/public/app/controllers/grafanaCtrl.js +++ b/public/app/controllers/grafanaCtrl.js @@ -33,9 +33,16 @@ function (angular, config, _, $, store) { $controller('DashboardCtrl', { $scope: viewScope }).init(dashboardData); }; - $rootScope.onAppEvent = function(name, callback) { + $rootScope.onAppEvent = function(name, callback, localScope) { var unbind = $rootScope.$on(name, callback); - this.$on('$destroy', unbind); + var callerScope = this; + if (callerScope.$id === 1 && !localScope) { + console.log('warning rootScope onAppEvent called without localscope'); + } + if (localScope) { + callerScope = localScope; + } + callerScope.$on('$destroy', unbind); }; $rootScope.appEvent = function(name, payload) { diff --git a/public/app/core/core.ts b/public/app/core/core.ts index 039b232dbf6..98f487b236f 100644 --- a/public/app/core/core.ts +++ b/public/app/core/core.ts @@ -18,8 +18,6 @@ export * from './directives/array_join' export * from './directives/give_focus' - -export * from './routes/bundle_loader' export * from './filters/filters' diff --git a/public/app/features/annotations/annotationsSrv.js b/public/app/features/annotations/annotationsSrv.js index a4529de2019..89c9b72ec1f 100644 --- a/public/app/features/annotations/annotationsSrv.js +++ b/public/app/features/annotations/annotationsSrv.js @@ -13,8 +13,8 @@ define([ var self = this; this.init = function() { - $rootScope.onAppEvent('refresh', this.clearCache); - $rootScope.onAppEvent('setup-dashboard', this.clearCache); + $rootScope.onAppEvent('refresh', this.clearCache, $rootScope); + $rootScope.onAppEvent('setup-dashboard', this.clearCache, $rootScope); }; this.clearCache = function() { diff --git a/public/app/features/dashlinks/module.js b/public/app/features/dashlinks/module.js index 23ce8c0ffae..6b5677e5d2d 100644 --- a/public/app/features/dashlinks/module.js +++ b/public/app/features/dashlinks/module.js @@ -159,7 +159,7 @@ function (angular, _) { }; updateDashLinks(); - $rootScope.onAppEvent('dash-links-updated', updateDashLinks); + $rootScope.onAppEvent('dash-links-updated', updateDashLinks, $rootScope); }); module.controller('DashLinkEditorCtrl', function($scope, $rootScope) { diff --git a/public/app/features/templating/templateValuesSrv.js b/public/app/features/templating/templateValuesSrv.js index 13e85d08a33..8c9404a32e6 100644 --- a/public/app/features/templating/templateValuesSrv.js +++ b/public/app/features/templating/templateValuesSrv.js @@ -18,7 +18,7 @@ function (angular, _, kbn) { if (variable) { self.updateAutoInterval(variable); } - }); + }, $rootScope); this.init = function(dashboard) { this.variables = dashboard.templating.list; diff --git a/public/app/plugins/datasource/elasticsearch/bucketAgg.js b/public/app/plugins/datasource/elasticsearch/bucketAgg.js index 86f35c09667..a8e56aa07f3 100644 --- a/public/app/plugins/datasource/elasticsearch/bucketAgg.js +++ b/public/app/plugins/datasource/elasticsearch/bucketAgg.js @@ -20,7 +20,7 @@ function (angular, _, queryDef) { $rootScope.onAppEvent('elastic-query-updated', function() { $scope.validateModel(); $scope.updateOrderByOptions(); - }); + }, $scope); $scope.init = function() { $scope.agg = bucketAggs[$scope.index]; diff --git a/public/app/plugins/datasource/elasticsearch/metricAgg.js b/public/app/plugins/datasource/elasticsearch/metricAgg.js index 26a0323013f..1fe393138d5 100644 --- a/public/app/plugins/datasource/elasticsearch/metricAgg.js +++ b/public/app/plugins/datasource/elasticsearch/metricAgg.js @@ -22,7 +22,7 @@ function (angular, _, queryDef) { $rootScope.onAppEvent('elastic-query-updated', function() { $scope.index = _.indexOf(metricAggs, $scope.agg); $scope.validateModel(); - }); + }, $scope); $scope.validateModel = function() { $scope.isFirst = $scope.index === 0; diff --git a/public/app/services/alertSrv.js b/public/app/services/alertSrv.js index 88885f4bd78..3d0f9e66ff2 100644 --- a/public/app/services/alertSrv.js +++ b/public/app/services/alertSrv.js @@ -13,14 +13,14 @@ function (angular, _) { this.init = function() { $rootScope.onAppEvent('alert-error', function(e, alert) { self.set(alert[0], alert[1], 'error'); - }); + }, $rootScope); $rootScope.onAppEvent('alert-warning', function(e, alert) { self.set(alert[0], alert[1], 'warning', 5000); - }); + }, $rootScope); $rootScope.onAppEvent('alert-success', function(e, alert) { self.set(alert[0], alert[1], 'success', 3000); - }); - $rootScope.onAppEvent('confirm-modal', this.showConfirmModal); + }, $rootScope); + $rootScope.onAppEvent('confirm-modal', this.showConfirmModal, $rootScope); }; // List of all alert objects diff --git a/public/app/services/utilSrv.js b/public/app/services/utilSrv.js index 12aa518e24c..b9e703443e4 100644 --- a/public/app/services/utilSrv.js +++ b/public/app/services/utilSrv.js @@ -9,7 +9,7 @@ function (angular) { module.service('utilSrv', function($rootScope, $modal, $q) { this.init = function() { - $rootScope.onAppEvent('show-modal', this.showModal); + $rootScope.onAppEvent('show-modal', this.showModal, $rootScope); }; this.showModal = function(e, options) {