diff --git a/src/app/app.js b/src/app/app.js index 41905a92955..973765c4f52 100644 --- a/src/app/app.js +++ b/src/app/app.js @@ -136,9 +136,12 @@ function (angular, $, _, appLevelRequire) { var $scope = this; $scope.requireContext(deps, function () { var deps = _.toArray(arguments); - $scope.$apply(function () { - fn.apply($scope, deps); - }); + // Check that this is a valid scope. + if($scope.$id) { + $scope.$apply(function () { + fn.apply($scope, deps); + }); + } }); }; }]); diff --git a/src/app/directives/kibanaPanel.js b/src/app/directives/kibanaPanel.js index 49283b8d00a..e37dc7862a2 100644 --- a/src/app/directives/kibanaPanel.js +++ b/src/app/directives/kibanaPanel.js @@ -61,16 +61,22 @@ function (angular) { link: function($scope, elem, attr) { // once we have the template, scan it for controllers and // load the module.js if we have any + var newScope = $scope.$new(); // compile the module and uncloack. We're done function loadModule($module) { $module.appendTo(elem); elem.wrap(container); /* jshint indent:false */ - $compile(elem.contents())($scope); + $compile(elem.contents())(newScope); elem.removeClass("ng-cloak"); } + newScope.$on('$destroy',function(){ + elem.unbind(); + elem.remove(); + }); + $scope.$watch(attr.type, function (name) { elem.addClass("ng-cloak"); // load the panels module file, then render it in the dom. diff --git a/src/app/services/dashboard.js b/src/app/services/dashboard.js index 768a3cbac62..4731d0bb928 100644 --- a/src/app/services/dashboard.js +++ b/src/app/services/dashboard.js @@ -134,6 +134,9 @@ function (angular, $, kbn, _, config, moment, Modernizr) { // here before telling the panels to refresh this.refresh = function() { if(self.current.index.interval !== 'none') { + if(_.isUndefined(filterSrv)) { + return; + } if(filterSrv.idsByType('time').length > 0) { var _range = filterSrv.timeRange('last'); kbnIndex.indices(_range.from,_range.to,