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/addPanel.js b/src/app/directives/addPanel.js index 2887a54a35e..4d7dee74901 100644 --- a/src/app/directives/addPanel.js +++ b/src/app/directives/addPanel.js @@ -12,6 +12,11 @@ function (angular, app, _) { return { restrict: 'A', link: function($scope, elem) { + + $scope.$on("$destroy",function() { + elem.remove(); + }); + $scope.$watch('panel.type', function() { var _type = $scope.panel.type; $scope.reset_panel(_type); diff --git a/src/app/directives/kibanaPanel.js b/src/app/directives/kibanaPanel.js index e7a9ddbdc84..505eaa6c7d0 100644 --- a/src/app/directives/kibanaPanel.js +++ b/src/app/directives/kibanaPanel.js @@ -13,7 +13,6 @@ function (angular) { '